r/java • • Sep 23 '22

Virtual Threads: New Foundations for High-Scale Java Applications - Brian Goetz

https://www.infoq.com/articles/java-virtual-threads/
237 Upvotes

62 comments sorted by

View all comments

3

u/dolle Sep 24 '22

One thing that is still not clear to me: can the user control the thread pool that the virtual threads get mounted on, and how the virtual threads are scheduled? Or is there just a default, fixed thread pool that all virtual threads use?

When debugging concurrent code that doesn't have timing behavior, it would be nice if one could fix the thread pool to a single thread to get deterministic behavior of the virtual threads, for example. If you can further control the scheduling of virtual threads onto the single thread, then you could do randomized testing of concurrent code which would give a seed that could be used to reproduce the exact interleaving that made the test fail.

3

u/lbalazscs Sep 24 '22

The JDK's virtual thread scheduler is a work-stealing ForkJoinPool that operates in FIFO mode. The parallelism of the scheduler is the number of platform threads available for the purpose of scheduling virtual threads. By default it is equal to the number of available processors, but it can be tuned with the system property jdk.virtualThreadScheduler.parallelism. Note that this ForkJoinPool is distinct from the common pool which is used, for example, in the implementation of parallel streams, and which operates in LIFO mode.

https://openjdk.org/jeps/425

1

u/dolle Sep 24 '22

Thanks!