Virtual thread = lightweight object

Not an OS thread. Just JVM state. Can create millions per JVM. Memory: ~200 bytes each vs ~1MB for platform thread.

Advertisement

Virtual thread = lightweight object

Not an OS thread. Just JVM state. Can create millions per JVM. Memory: ~200 bytes each vs ~1MB for platform thread.

Advertisement

Carrier threads

Small pool of OS threads (typically = CPU count). Virtual threads mount on a carrier to execute.

Unmount on blocking I/O

When VT blocks on I/O, it unmounts from carrier. Carrier runs another VT. When I/O completes, VT re-mounts.

Pin gotchas

synchronized blocks pin VT to carrier — blocks unmount. Use ReentrantLock instead.

When to use

I/O-bound workloads: HTTP calls, DB queries, message consumers. CPU-bound work: use platform threads.