Java 21 virtual threads, a year later
Virtual threads changed how I write blocking Java services, but they did not repeal backpressure, connection pools, or physics. What held up, what did not, and the defaults I use now.
Java 21 made virtual threads a finished feature, and a year of using them in anger has settled into a fairly clear picture for me. They are a real improvement to how server-side Java gets written. They are also widely misunderstood in one specific way: people treat them as a scalability feature, when they are really a programming model feature.
1. What they actually give you#
The classic problem is simple. A thread-per-request service does mostly blocking work: read a request, call a database, call two services, write a response. Platform threads are too expensive to give one to every request, so we built async and reactive machinery to share them, and paid for it with stack traces that read like ransom notes and code nobody wants to debug at 3 a.m.
Virtual threads give the threads back. You write straight-line blocking code, the runtime parks the virtual thread when it blocks, and a small pool of carrier threads does the actual running. The code looks like 2009 and scales like it should.
2. Where they shine#
Anywhere the work is I/O bound and the concurrency is naturally per-request: API gateways, CRUD services, fan-out calls to internal systems, report generation. In these services I have happily deleted reactive plumbing and replaced it with ordinary code that a new hire can read. That readability is not a soft benefit. It is most of the benefit.
They also pair well with structured concurrency thinking, even informally: start the calls a request needs, join them, cancel what is left when one fails decisively. Timeouts become simple again.
3. Where they do not help#
Virtual threads do not create resources. If your database pool has 40 connections, the 41st request waits, exactly as before, except now it waits with cheaper threads. That is better, but it is not more throughput. CPU-bound work gains nothing at all; a virtual thread doing math occupies a carrier thread the whole time.
Backpressure also does not disappear. It moves. With unbounded virtual threads, an overloaded downstream now receives more concurrent load instead of your service shedding it at the thread pool boundary. You need semaphores and bulkheads in the places you used to rely on pool sizes, and you need them deliberately.
4. The pinning trap#
The famous footgun is pinning: a virtual thread that blocks inside a synchronized block, or inside a native call, cannot be unmounted, so it holds its carrier thread hostage. A year on, the practical rules are simple. Prefer ReentrantLock where the lock is held across blocking calls, watch for old libraries that synchronize around I/O, and run with the pinning trace turned on in staging so you find them before production does. The JDK keeps improving here, but libraries age slower than runtimes.
5. My defaults now#
For new I/O bound services, I start with virtual threads and blocking code, sized pools for the actual scarce resources, and explicit concurrency limits at service boundaries. I reach for reactive streams when the problem is genuinely a stream: continuous data, fine-grained flow control, complex merging. Both models are tools. The win of the last year is that the simple tool is back on the table.
