213. Explaining how virtual threads work
Now that we know how to create and start a virtual thread, let’s see how they actually work.
Let’s start with a meaningful diagram:
Figure 10.7: How virtual threads work
As you can see, Figure 10.7 is similar to Figure 10.6, except that we have added a few more elements.
First of all, notice that the platform threads run under a ForkJoinPool
umbrella. This is a First-In-First-Out (FIFO) dedicated fork/join pool, dedicated to scheduling and orchestrating the relationships between virtual threads and platform threads (detailed coverage of Java’s fork/join framework is available in Java Coding Problems, First Edition, Chapter 11).
Important note
This dedicated ForkJoinPool
is controlled by the JVM, and it acts as the virtual thread scheduler based on a FIFO queue. Its initial capacity (i.e., the number of threads) is equal to the number of available cores, and it can be increased to...