Not resuming Virtual Threads?
Alan Bateman
Alan.Bateman at oracle.com
Fri Jul 3 18:53:07 UTC 2020
On 03/07/2020 19:25, Johannes Kuhn wrote:
> Hi Ron,
>
> It's sad to hear that Continuations will not be exposed, at least not
> at first.
>
> But it does not solve or hide that issue.
>
> Your Argument is only valid if every submitted Runnable to an Executor
> is eventually called.
> If this is not the case, then you have a bug in the Scheduler - at
> least if I understood you correctly.
>
> The default implementation of the Scheduler is a ForkJoinPool, which
> comes with a shutdown() method.
>
> I'm probably missing a big chunk of stuff here. It looks for me, that
> by shutting down the executor, you basically cancel all virtual
> threads that are currently yielding.
> How are their held locks released? (Compare with Thread.terminate())
>
> In the example at [1], the finally block is never executed. You might
> argument that this is a constructed example, and it is.
> Still not sure if I want to debug something like that in production.
There isn't an API to get a reference to the default scheduler so it
should never be shutdown.
Bring your own scheduler comes with the responsibility of using it
correctly. In your example you are shutting it down mid-flight so none
of the threads created to use that scheduler can continue. If someone
does that then I agree it might be hard to debug but there is only so
much we can do to identify bugging code.
-Alan
More information about the loom-dev
mailing list