开发者

future.get returning before finally executed in Callable on cancel

开发者 https://www.devze.com 2023-04-07 19:58 出处:网络
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:

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 succ开发者_开发知识库essful 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?


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".

0

精彩评论

暂无评论...
验证码 换一张
取 消