future.get returning before finally executed in Callable on cancel
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".
精彩评论