Docs for ExecutorService#close and canceled tasks

Alan Bateman alan.bateman at oracle.com
Sun Jan 5 17:32:03 UTC 2025


On 05/01/2025 10:20, Fabian Meumertzheim wrote:
> Hi,
>
> I recently traced a race in an application
> (https://github.com/bazelbuild/bazel/issues/21773) down to a
> particular behavior of ExecutorService#close that, to me, doesn't seem
> to be obvious from its documentation: If a task that has been
> submitted to the executor is canceled while it is already executing,
> ExecutorService#close will not wait for the associated Runnable to
> return.
Thanks for bringing this up. TPTE interpreted "all tasks have completed 
execution" to mean all tasks done (Future::isDone) whereas it may have 
been better to have followed TPE and FJP and wait for all threads to 
have completed the tasks. So yes, some spec clarification may be needed 
here but it will need to take into account other ExecutorService 
implementation that may exist elsewhere. In addition, we need to think 
about changing TPTE to avoid the surprising behavior.

-Alan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20250105/1cd31ab7/attachment-0001.htm>


More information about the core-libs-dev mailing list