Can't yield from within an instance created by reflection

Ron Pressler ron.pressler at oracle.com
Thu Apr 8 17:50:34 UTC 2021


As Alan said, you should use the j.u.c classes and *not* touch the number of workers in the scheduler, but you might also want to take a look at setting custom schedulers for virtual threads: https://download.java.net/java/early_access/loom/docs/api/java.base/java/lang/Thread.Builder.OfVirtual.html#scheduler(java.util.concurrent.Executor)

This should give you pretty much the same capabilities as continuations.

— Ron

On 7 Apr 2021, at 10:44, Øystein Myhre Andersen <o.myhre at gmail.com<mailto:o.myhre at gmail.com>> wrote:

Well, I use Object.wait to ensure only one coroutine is operating at a time.
How do I increase this maximum value ?

I will also try rewriting using  java.util.concurrent locks

- Øystein

On Wed, Apr 7, 2021 at 11:17 AM Alan Bateman <Alan.Bateman at oracle.com<mailto:Alan.Bateman at oracle.com>>
wrote:

On 07/04/2021 09:57, Øystein Myhre Andersen wrote:

Is there a limit to the number of virtual threads ?

The error in my implementation of class Simulation occurs when I start virtual thread number 257.

Is this just a coincidence or ....

Virtual threads are just objects in the heap and 1M virtual threads
shouldn't be an issue. I suspect David is right that you've got threads
pinned due to Java monitors and synchronization (you also mentioned
"oversynchronization" in one of your mails). The scheduler is based on
ForkJoinPool and it's setup to spin up additional underlying carrier
threads to help when there are virtual threads blocked in Object.wait. The
default maximum is 256. Can you say a bit more about the locking that you
are using when the Simula coroutines are implemented with threads? Would it
be hard to convert it to use java.util.concurrent locks?

-Alan




More information about the loom-dev mailing list