TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Java’s Mysterious Interrupt

125 点作者 mattiemass大约 7 年前

4 条评论

amarkov大约 7 年前
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 未加载
Animats大约 7 年前
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 未加载
lenkite大约 7 年前
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 未加载
anameaname大约 7 年前
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 未加载