Java / Java 21 Virtual Threads Interview questions
How is a virtual thread mounted onto a carrier thread?
Mounting is the act of a carrier thread picking up a virtual thread's continuation and executing its code. Unmounting is the reverse: detaching that continuation so the carrier is free for other work.
When the scheduler assigns a runnable virtual thread to an idle carrier, the JVM restores (thaws) the virtual thread's saved stack state onto that carrier and execution continues from where it left off.
Crucially, a virtual thread isn't guaranteed to resume on the same carrier thread it started on - each mount/unmount cycle can land it on a different one, which is fine since a virtual thread's identity is independent of any particular OS thread.
More Related questions...