A carrier thread is a platform thread used by the JDK to run a virtual thread while that virtual thread is mounted for execution. When the virtual thread reaches a blocking operation, the JDK can save its state, unmount it, and let another virtual thread use the carrier thread. After the operation completes, the original virtual thread resumes on a carrier thread, which may be different from the previous one. section 8.5
Carrier-thread behavior has important limits:
- Pinning prevents unmounting when blocking occurs inside a synchronized block or while a native Java Native Interface call remains on the stack, leaving the carrier thread blocked as well. section 8.5.2
- Long-running CPU-bound work can monopolize a carrier thread because the virtual-thread scheduler cannot interrupt a running thread unless it yields through an I/O operation. section 8.5.2
- Virtual threads are therefore most useful for applications with substantial I/O, rather than for computation-heavy workloads. section 8.5.2
Figure 8.6 Virtual thread execution model with I/O request handling
Trace how a virtual thread occupies a carrier thread, yields during an I/O request, and later resumes execution. section 8.5
