Java / Java 21 Virtual Threads Interview questions
Why do we use virtual threads instead of traditional thread pools?
A traditional bounded thread pool caps concurrency at a fixed number of OS threads. Under heavy I/O-bound load, once every pooled thread is blocked waiting on something slow, new work simply queues up, adding latency even though the CPU is mostly idle.
Virtual threads remove that ceiling: because they're cheap to create and don't consume an OS thread while blocked, you can run one virtual thread per incoming request or task without careful pool-size tuning.
This also avoids the operational complexity of choosing the "right" pool size, a value that's notoriously hard to get right and often changes with load patterns and hardware.
More Related questions...