Skip to content
Commitwise
Menu

Virtual thread

A lightweight Java thread managed by the JVM, cheap enough to create one per task and to block.

Definition

Virtual threads (Java 21+) run on a small pool of operating-system carrier threads. When a virtual thread blocks on I/O or sleeps, the JVM unmounts it and runs another one on the same carrier, so ordinary blocking code can serve tens of thousands of concurrent tasks. They don't make code faster or prevent data races, and they move the bottleneck to limited resources like connection pools.

In practice

Executors.newVirtualThreadPerTaskExecutor() can run 10,000 tasks that each sleep one second in about one second.

Learn it in context

Lessons that use this term.

Related terms

Esc

Type to search the whole site.