Quick revision
The short answer
Carrier threads are the platform threads of a ForkJoinPool that the virtual thread scheduler uses to run virtual threads. A running virtual thread is mounted on a carrier, so its frames execute on that carrier's OS thread. When it calls a blocking socket read that the JDK has adapted, its stack frames are saved to the heap and it unmounts, freeing the carrier for other work; when data arrives, the virtual thread is scheduled again, possibly on a different carrier. Throughout, Thread.currentThread() returns the virtual thread, never the carrier.
What to remember
In this answer, we saw that carriers are platform threads in the scheduler's ForkJoinPool and that a running virtual thread is mounted on one, executing its frames on that carrier's OS thread. On a blocking socket read, the JDK reads in non-blocking mode, registers the socket with a poller and parks the virtual thread, saving its frames to the heap and freeing the carrier. When data arrives, the poller unparks it and it is mounted again, possibly on another carrier. Through all of this, Thread.currentThread() returns the virtual thread, and operations that cannot unmount either compensate with an extra carrier or pin.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Carrier threads are the platform threads of a ForkJoinPool that the virtual thread scheduler uses to run virtual threads. A running virtual thread is mounted on a carrier, so its frames execute on that carrier's OS thread. When it calls a blocking socket read that the JDK has adapted, its stack frames are saved to the heap and it unmounts, freeing the carrier for other work; when data arrives, the virtual thread is scheduled again, possibly on a different carrier. Throughout, Thread.currentThread() returns the virtual thread, never the carrier.
Why this question is asked
Mounting and unmounting are the mechanism behind everything virtual threads promise. If we understand them, we can explain why blocking code scales, why some operations still hold a carrier, and why a thread dump looks the way it does. Interviewers ask this internals question to see whether we have a working mental model rather than a slogan. In this answer, we will recap what carriers are, follow one virtual thread through a blocking socket read step by step, look at how the JDK makes a blocking read non-blocking underneath, and see what our own code observes along the way.
1A Quick Recap: Virtual Threads and Carriers
A virtual thread is a java.lang.Thread that the JVM schedules itself. It cannot run on its own; it needs an OS thread to execute its instructions. The JVM lends it one: a carrier, which is an ordinary platform thread belonging to the virtual thread scheduler. By default the scheduler is a ForkJoinPool working in FIFO mode, with about as many carriers as there are CPU cores, so an 8-core machine has about 8 carriers no matter how many virtual threads exist.
Mounting means attaching a virtual thread to a carrier so that it runs; unmounting means detaching it so that the carrier can run something else. A virtual thread is mounted only while it is actually doing work.
2Step by Step: A Blocking Socket Read
Let us follow one virtual thread that handles a request and reads a reply from a database over a socket.
7 messages in order. Play them, or step through them one at a time.
The carrier is never blocked; only the virtual thread waits.
The scheduler picks a free carrier, here worker-3, and mounts req-17 on it. The virtual thread's frames now execute on worker-3's OS thread. Then req-17 calls read(), and no data has arrived yet.
In a platform thread, read() would block in the kernel and the OS thread would sit idle until data came. Here the JDK does something different. The socket is in non-blocking mode underneath, so the read returns immediately with no data. The JDK then registers the socket with a poller, a JDK thread that waits for many sockets at once using the OS's event mechanism, such as epoll on Linux or kqueue on macOS. Then the virtual thread parks.
Parking a virtual thread is where unmounting happens. Its frames, the part of its stack that lives on the carrier, are copied into a stack chunk object on the heap, and the carrier returns to the scheduler to run the next virtual thread in its queue. Worker-3 is free; req-17 now exists only as an object on the heap, waiting.
When the database's reply arrives, the poller sees the socket become readable and unparks req-17. Unparking does not run it immediately; it submits it to the scheduler as a task. Some carrier, here worker-6, picks it up, the frames are copied back onto that carrier's stack, and read() is tried again, this time returning data. From the code's point of view, read() simply blocked and then returned n bytes.
3Why the JDK Had to Adapt Each Blocking Operation
This only works because the JDK's own implementation of the socket read knows how to park a virtual thread instead of blocking the carrier. The JDK team reimplemented java.net sockets and other blocking APIs, such as java.nio channels, Thread.sleep, the locks and queues in java.util.concurrent and many others, so that when called from a virtual thread they park rather than block the OS thread. Our code calls exactly the same methods as before.
Not every operation could be adapted in the same way. Some file system operations block in the OS with no readiness mechanism to wait on; for those the JDK compensates by temporarily adding a carrier to the pool while one is blocked, so other virtual threads keep running. And when a virtual thread cannot unmount at all, for example while a native method is on its stack, or inside synchronized before JDK 24, it is pinned: it blocks while still mounted and holds its carrier for the whole wait.
| Operation | From a virtual thread | Carrier |
|---|---|---|
| Socket read or write | parks, poller watches the socket | freed |
Thread.sleep, LockSupport.park | parks with a timer or until unpark | freed |
ReentrantLock, BlockingQueue | parks | freed |
| Some file I/O | blocks in the OS | held; pool compensates with an extra carrier |
| Native method on the stack | pinned, blocks mounted | held |
| synchronized (before JDK 24) | pinned when blocking inside it | held |
4What Our Code Observes
Notice in the example that Thread.currentThread() returned the same virtual thread before and after the read, even though it ran on two different carriers. Our code always sees the virtual thread: its name, its id, its ThreadLocal values and its interrupt status. The carrier is deliberately hidden. The string form shows the carrier after the @ sign only as diagnostic information.
This hiding is why existing code keeps working: a ThreadLocal set before the read still holds its value after it, because the values belong to the virtual thread, not to the carrier. It also means we must not rely on running on the same OS thread across a blocking call, which matters only for unusual code such as native libraries that keep per-OS-thread state.
5What This Means for Capacity
Because a carrier is freed during every adapted blocking call, a few carriers can serve a very large number of virtual threads, as long as each thread does little CPU work between waits. A request that spends 2 milliseconds on the CPU and 98 milliseconds waiting on the network occupies a carrier only 2 percent of the time, so one carrier can keep about 50 such requests in progress, and 8 carriers about 400 at full CPU use, with thousands more parked cheaply on the heap. The real limits become CPU time and downstream resources, not threads.
6Follow-up questions
Is unmounting expensive?
It costs copying the frames that are on the carrier's stack into a heap object, and later copying them back, which is done lazily for the frames actually needed. That is typically far cheaper than an OS context switch, and it happens only when the virtual thread would have blocked anyway.
Can I control which carrier a virtual thread runs on?
No. There is no supported API to choose or pin a carrier, and the scheduler is free to move a virtual thread to any carrier each time it is mounted. Code must not depend on the OS thread it runs on.
Does the poller thread become a bottleneck?
It handles readiness events only, not the I/O work itself, and one poller can watch a very large number of sockets with the OS event mechanism. The JDK can use more than one poller; check your version for the details.
7Conclusion
In this answer, we saw that carriers are platform threads in the scheduler's ForkJoinPool and that a running virtual thread is mounted on one, executing its frames on that carrier's OS thread. On a blocking socket read, the JDK reads in non-blocking mode, registers the socket with a poller and parks the virtual thread, saving its frames to the heap and freeing the carrier. When data arrives, the poller unparks it and it is mounted again, possibly on another carrier. Through all of this, Thread.currentThread() returns the virtual thread, and operations that cannot unmount either compensate with an extra carrier or pin.
Open with
Carriers are just platform threads in a ForkJoinPool that the virtual thread scheduler owns, by default about one per CPU core. A virtual thread can't execute by itself, so when it's runnable the scheduler mounts it on a free carrier, and its frames run on that carrier's OS thread.
Then, if they want more
Now say it calls read on a socket and there's no data. The JDK's socket implementation is non-blocking underneath, so instead of blocking in the kernel, it registers the socket with a poller thread that uses epoll or kqueue, and parks the virtual thread.
Parking is where it unmounts: the frames on the carrier's stack are copied into a stack chunk object on the heap, and the carrier goes back to the scheduler to run another virtual thread.
When data arrives, the poller unparks it, which submits it to the scheduler, and some carrier, maybe a different one, mounts it, restores the frames, and read returns. Our code never notices. Thread.currentThread always returns the virtual thread, so its name, id and thread-locals are the same before and after, and the carrier is hidden.
The exceptions are operations that can't unmount, like a native method on the stack, or synchronized before JDK 24, where the thread is pinned and holds the carrier.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 24
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- JEP 444, Virtual Threads
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Explain mounting and unmounting: what happens when a virtual thread calls a blocking...": https://scrivio-interview-library.netlify.app/java/virtual-threads/85b8ce37a2/