Java / Java 21 Virtual Threads Interview questions
Which is better and why: thread pools or virtual threads for I/O-heavy services?
For most I/O-heavy services, virtual threads are the better fit: each request can hold its own thread through the entire blocking call chain without consuming a scarce OS thread, removing the pool-exhaustion queueing that limits a fixed-size platform thread pool and letting you keep straightforward, synchronous code.
That said, virtual threads don't eliminate the need to bound concurrency - if a downstream dependency like a database only supports, say, 50 concurrent connections, unlimited virtual threads will just shift the bottleneck there and can overwhelm it faster than a bounded pool would have.
The right approach is usually virtual threads at the request-handling layer, combined with an explicit bound (a Semaphore or a bounded connection pool) around the specific resource that actually has a hard limit, rather than relying on platform-thread scarcity as an implicit throttle.
More Related questions...