Quick revision
The short answer
Virtual threads raise throughput when many tasks spend most of their time waiting; they do not make any single task faster. So they do not help with CPU-bound work, because there are still only as many carrier threads as cores; with low concurrency, where a few threads were already enough; when a downstream resource such as a connection pool or the database is the real limit; or when the code is already non-blocking, as in reactive pipelines.
What to remember
In this answer, we saw that virtual threads make waiting cheap, so they raise throughput only when the number of threads was the limit. By Little's law, they increase how many requests can be in progress, not how fast each one runs. They do not help CPU-bound work, which is limited by cores; low-concurrency services, which never lacked threads; systems limited by a downstream resource such as a connection pool; or code that is already non-blocking. And they never reduce the latency of a single task.
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.
Virtual threads raise throughput when many tasks spend most of their time waiting; they do not make any single task faster. So they do not help with CPU-bound work, because there are still only as many carrier threads as cores; with low concurrency, where a few threads were already enough; when a downstream resource such as a connection pool or the database is the real limit; or when the code is already non-blocking, as in reactive pipelines.
Why this question is asked
Virtual threads are often presented as a performance switch, and teams turn them on expecting every service to get faster. When it does not happen, the disappointment usually comes from a misunderstanding of what they change. Interviewers ask this question to see whether we can predict the benefit before trying it, which is what keeps us from wasting time or blaming the wrong thing. In this answer, we will recap what virtual threads actually improve, use Little's law to see where the gain comes from, and then walk through each case where they do not help and why.
1A Quick Recap of What Virtual Threads Change
A virtual thread is a thread managed by the JVM rather than the operating system. Many virtual threads run on a small pool of platform threads called carriers, by default one per CPU core. When a virtual thread blocks on I/O, for example waiting for a database reply, the JVM unmounts it, parks it in memory, and gives the carrier to another virtual thread. When the reply arrives, the thread is mounted again and continues.
So the thing that becomes cheap is waiting. A blocked platform thread holds an operating system thread and its stack; a blocked virtual thread holds only a small object in the heap. That lets us have a hundred thousand tasks waiting at the same time instead of a few hundred. Nothing about this makes the CPU run code faster.
2Where the Gain Comes From: Little's Law
Little's law connects three numbers for any system in a steady state: the number of requests in progress equals the arrival rate times the time each one spends inside. Written for a service, concurrency = throughput x latency. If each request takes 100 ms, mostly waiting on I/O, and we have 200 threads, the service can complete at most 200 / 0.1 = 2,000 requests per second, no matter how idle the CPU is.
Notice what moves in that calculation. Latency stays at 100 ms; virtual threads only raise the number of requests that can be in progress at once. That gives us the general rule: virtual threads help when throughput is limited by the number of threads, and only then. Each case below is a situation where something else is the limit.
3Case 1: CPU-Bound Work
If a task spends its time computing, such as resizing images, compressing data or running a pricing model, it never blocks, so there is nothing to unmount. Eight cores can run eight computations at a time whether those computations sit on platform threads or virtual threads. Adding more threads just makes them take turns. Virtual threads also do not time-slice fairly the way the OS scheduler does, so a long computation holds its carrier until it finishes or blocks. For CPU-bound work, a platform thread pool sized to the number of cores remains the right tool.
4Case 2: Low Concurrency
If a service handles 50 requests per second with 20 ms latency, Little's law says it has about one request in progress at a time. A pool of 200 platform threads is already mostly idle. Switching to virtual threads changes nothing measurable, because the service was never short of threads. The same goes for a batch job that processes items one by one, or a command-line tool. Virtual threads matter when the number of tasks waiting at once is in the thousands, not when it is in the tens.
5Case 3: A Downstream Resource Is the Limit
Often the real cap is not our threads but what they wait for. If every request needs one of 10 database connections for 50 ms, the service can complete at most 200 requests per second, and that is true with 200 threads or with 200,000. Virtual threads only change where the extra requests wait: before, they queued for a thread; now, they queue for a connection, and may hit the pool's timeout. The same applies to a rate-limited partner API or a database that is already at full CPU. The fix there is to reduce the time each request holds the resource, or to add capacity to the resource itself.
| Situation | What limits throughput | Effect of virtual threads |
|---|---|---|
| Many requests waiting on I/O | Number of threads | Large gain |
| CPU-bound computation | Number of cores | None |
| Few concurrent requests | Nothing; threads are idle | None |
| Small connection pool or slow database | The downstream resource | None; the queue moves to the pool |
| Reactive, non-blocking code | Already few threads | Little; no blocking to unmount |
6Case 4: Code That Is Already Non-Blocking
A reactive service, for example on WebFlux with Netty and R2DBC, already avoids the problem virtual threads solve. It never blocks a thread while waiting; it registers a callback and runs on a handful of event loop threads. Its concurrency is not limited by thread count in the first place, so moving it to virtual threads does not raise throughput. The reasons to choose virtual threads there are about simpler code and easier debugging, not speed.
7Latency of a Single Task Does Not Go Down
Finally, a single request is not faster on a virtual thread. A database query that takes 40 ms takes 40 ms; mounting and unmounting even adds a tiny cost. If users complain that one endpoint is slow while the service is not overloaded, the problem is in the work itself, and the answer is profiling, better queries or caching. When virtual threads do improve latency, it is indirectly: under heavy load, requests no longer queue for a thread, so the waiting time that came from the thread pool disappears.
8Follow-up questions
Can virtual threads ever make things worse?
Yes, in a few ways. Removing the thread pool's cap can overload a database or a partner API that the pool used to protect. Libraries that cache large objects in ThreadLocals use more memory with many threads. And on JDK 21 to 23, blocking inside synchronized pins the carrier, which can stall a service. Each needs an explicit limit or a newer JDK.
How do I know in advance whether my service will benefit?
Measure where requests spend their time. If most of the latency is waiting on I/O and the thread pool is saturated during peaks, while the CPU and downstream resources have headroom, virtual threads will help. If the CPU is high or a connection pool is always full, they will not.
Should CPU-bound tasks avoid virtual threads entirely?
Running a short computation on a virtual thread is harmless; what matters is how many we run at once. For a pool of heavy computations, a platform-thread executor sized to the cores keeps concurrency at the right level and leaves the carriers free for the I/O-bound virtual threads in the same process.
9Conclusion
In this answer, we saw that virtual threads make waiting cheap, so they raise throughput only when the number of threads was the limit. By Little's law, they increase how many requests can be in progress, not how fast each one runs. They do not help CPU-bound work, which is limited by cores; low-concurrency services, which never lacked threads; systems limited by a downstream resource such as a connection pool; or code that is already non-blocking. And they never reduce the latency of a single task.
Open with
Virtual threads make blocking cheap, so they help when a service has many concurrent tasks that spend most of their time waiting and the number of threads is what limits throughput.
Then, if they want more
By Little's law, concurrency equals throughput times latency, so they raise how many requests can be in progress, not how fast any one of them runs. That gives four cases where they do not help.
CPU-bound work, like image processing or compression, never blocks, and there are still only as many carriers as cores, so eight cores compute eight things at a time either way; I would keep a platform pool sized to the cores. Low concurrency: if a service has a handful of requests in flight, its threads were idle already.
A downstream limit: if every request needs one of 10 connections for 50 ms, the service tops out at 200 requests per second no matter how many threads it has; the queue just moves from the thread pool to the connection pool.
And code that is already non-blocking, like a WebFlux and R2DBC service, has no blocking to unmount, so the benefit there would be simpler code, not throughput. Finally, a single slow request stays slow; that needs profiling, not a different thread type.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 21
- 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 "In which cases do virtual threads not improve performance, and why?": https://scrivio-interview-library.netlify.app/java/virtual-threads/81f9845474/