future.get 在取消时最终在 Callable 中执行之前返回
我有一个测试间歇性失败,当 future 被取消时, future.get 调用在 Callable 中执行 finally 块之前返回。这是基本工作流程:
future.cancel(true);
我看到 Callable
中抛出了 InterrupedException
主线程捕获 CancellationException<来自
future.get
调用的 /code>
现在,Callable
调用 finally
。
测试在我的笔记本上总是成功的,但在我们的构建服务器上大部分时间都失败。我的笔记本和构建服务器都运行 OpenJDK 1.7。有什么想法吗?
I'm have a test that is failing intermittently where a future.get call is returning before the finally block is executed in the Callable, when the future is canceled. Here's the basic workflow:
future.cancel(true);
I see the InterrupedException
thrown in the Callable
The main thread catches CancellationException
from the future.get
call
Now the Callable
calls finally
.
The test is always successful on my notebook and fails most of the time on our build server. Both my notebook and the build server are running OpenJDK 1.7. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
cancel()
的文档似乎没有指定它等待被中断的线程退出。如果你想要这样的保证,你必须设置一个监视器或其他一些同步机制,使取消者可以等待处理器说“我已经完成了我的finally块”。The documentation of
cancel()
doesn't seem to specify that it waits for the interrupted thread to exit. If you want that guarantee, you'll have to set up a monitor or some other synchronization mechanism whereby the canceler can wait for the processor to say "I'm done with my finally-block".