JEP 425 (Virtual Threads) - Cancellation

Alan Bateman Alan.Bateman at oracle.com
Mon May 2 07:42:14 UTC 2022


On 01/05/2022 23:04, Attila Kelemen wrote:
> While the cheapness of virtual threads does somewhat solve the issue
> of canceling only subtasks by allowing me to start a virtual thread with little
> cost, and interrupt it separately, it does not solve other issues. One big
> pain of mine is that blocking I/O is often uninterruptible (and not even
> cancelable by other means), and as far as I understand, this won't change.
Search for the sentence "To allow for interruption and cancellation, the 
blocking I/O methods ..." in the Networking section of the JEP as it 
deals with this topic.


> One solution would be of course is to allow providing the virtual threads
> a cancellation token upon creation, and let the virtual thread scheduler to
> throw a `VirtualThreadCancelledException` (or something similar) in some
> well defined cases (definitely not just at any safepoint). Of course, this
> exception has to be unchecked, and preferably not extend `Exception`
> to avoid people wrapping it left and right. With this the current interruption
> mechanism could be deprecated as well.
>
> Can we expect a similar cancellation mechanism to be considered?
As David said, this is more in the area of the (still in draft) 
Structured Concurrency JEP. There have been several prototypes that 
explored the cancellation space. The draft JEP has an explicit non-goal 
to provide a new cancellation mechanism but leaves the door open to 
re-visiting in a future JEP.

-Alan


More information about the jdk-dev mailing list