[concurrency-interest] Improving ThreadPoolExecutor.shutdownNow guarantees

Doug Lea dl at cs.oswego.edu
Fri Jun 16 15:27:55 EDT 2006

The return value of ThreadPoolExecutor.shutdownNow was not very
well-defined, either in spec or implementation. This method claimed
to return a list of tasks that had not run. But:
   1. What about tasks that are in the midst of being entered DURING
      the call to shutdownNow?
   2. Are those tasks deleted from the task queue upon return?

There were no official answers, but the unofficial
answer to the first question was: no answer -- they might
be dropped, rejected, returned in list, or sit in queue.
And the answer to the second was no, which because of the
first issue, meant that you could not rely on queue state.

There's probably not any code out there that depends on these
details, but we still want to get them right after noticing
how crummy this situation is. So, we improved
this to guarantee that ALL tasks (even those in the midst of
being entered) are run, rejected or returned in list (exactly one
of these), and remove them from queue upon return from shutdownNow,
which guarantees that traversals of results from multiple calls
won't encounter them multiple times.

This change probably won't make Mustang (which means that it might
be a while before they get into any Sun release) but we'd welcome
any comments or suggestions about them. You can find details in
CVS versions of code base.


More information about the Concurrency-interest mailing list