liveBook · Manning

Carrier thread

As explained in Quarkus in Action

A carrier thread is a platform thread that runs a virtual thread when the virtual thread is mounted for execution.

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
figure

Trace how a virtual thread occupies a carrier thread, yields during an I/O request, and later resumes execution. section 8.5

How Quarkus in Action covers it

How deep it goes
Details mounting, unmounting, resumption, pinning, and CPU monopolization, but stops short of implementation internals beyond JDK behavior.
Examples
Uses an I/O request execution diagram and examples involving synchronized blocks, native calls, and CPU-bound computation.
What you can do after
Evaluate virtual-thread execution by identifying carrier-thread release, pinning conditions, and CPU-bound monopolization.
How it connects
Connects carrier threads with virtual threads, platform threads, blocking I/O, reactive programming, event loops, and native calls.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Quarkus in Action. The section links point to the parts of the book it draws on.