Java / Java 21 Virtual Threads Interview questions
How does the JVM schedule virtual threads?
By default, virtual threads are scheduled by a dedicated ForkJoinPool instance running in FIFO mode, separate from the common pool used by parallel streams.
Each worker in that pool acts as a carrier thread. When a virtual thread becomes runnable (freshly started, or resumed after a blocking operation completes), it's queued onto the scheduler, and any idle carrier thread work-steals it to run.
Scheduling decisions happen at well-defined points: thread start, blocking I/O, Thread.sleep(), lock acquisition, and explicit yielding - not via OS-level time-slicing preemption the way platform threads are scheduled.
More Related questions...