Java / Java 21 Virtual Threads Interview questions
Why should you avoid pooling virtual threads?
Pooling exists to amortize an expensive resource - creating a platform thread costs a native stack allocation and OS bookkeeping, so reusing a small set of them made sense.
Virtual threads flip that assumption: creating one costs little more than allocating a small object on the heap. Pooling them adds bookkeeping overhead for no benefit, and worse, it reintroduces the very concurrency ceiling virtual threads were designed to remove, since a pool caps how many can run at once.
The official guidance is simple: never pool virtual threads - create a fresh one per task and let it terminate when the task is done.
More Related questions...