Non-obvious behavior in newVirtualThreadPerTaskExecutor

Alan Bateman alan.bateman at oracle.com
Tue Dec 2 07:52:47 UTC 2025


On 01/12/2025 22:38, Stig Rohde Døssing wrote:
> :
>
> If the main thread is only sent a single interrupt, then by the time 
> ExecutorService.close is called, the main thread will no longer be 
> interrupted, since that flag is cleared when the InterruptedException 
> is thrown.
>
Right, in the example, the interrupted status is cleared by Future::get 
when it throws InterruptedException, and the translation of 
try-with-resources means the close method does not have a reference to 
the "pending exception".

In general, cancellation and shutdown is difficult topic, and a big 
motivation for the StructuredTaskScope API.

-Alan


More information about the loom-dev mailing list