TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Java’s Mysterious Interrupt

125 pointsby mattiemassabout 7 years ago

4 comments

amarkovabout 7 years ago
For an embarrassing amount of time, I didn't even realize Java interrupt() could only interrupt blocking operations. I guess I thought they were like hardware interrupts, capable of just showing up anywhere without the program's cooperation.
评论 #17006786 未加载
Animatsabout 7 years ago
It&#x27;s more like thread cancellation than an interrupt.<p>Few languages do cancellation well. Either it doesn&#x27;t work right, or it does something overly elaborate like LISP breaks.
评论 #17008848 未加载
评论 #17010272 未加载
lenkiteabout 7 years ago
Making InterruptedException a <i>checked</i> exception was a _mind-boggling_ stupid design mistake that should have been immediately corrected but unfortunately never was. I always wince when writing scalable, long-running concurrent Java code. You need to interrupt and handle interrupts when tasks are hung, but you then need either litter up all your Java interfaces or do lots of exception detection juggling.
评论 #17009233 未加载
anameanameabout 7 years ago
As another surprising thing, calling interrupted() actually clears the interrupted bit. If it&#x27;s true, you pretty much have to throw InterruptedException. Otherwise, you have to re set the bit, and exit quietly.
评论 #17007510 未加载