Introduction and pitfalls of Java's new concurrency mode
summary
Java 21 adds virtual threads and structured concurrency and claims a cheap thread‑per‑task model: startVirtualThread or startVirtualThread and Executors.newVirtualThreadPerTaskExecutor spawn many lightweight threads (the demo reaches 100,000 threads), using carrier threads with mounting/unmounting to copy stacks to the heap. Pitfalls include methods that cause pinning (synchronized/native calls), thread‑locals leaking in pools, legacy libraries that pin, worse performance for long CPU‑bound tasks, and the need to measure rather than assume wins.
AI-written summary · about
chapters (8)
- 0:00Java’s new concurrency model
- 2:44Platform threads pitfalls
- 5:36Virtual threads improve concurrency
- 10:16Virtual threads lifecycle
- 14:35Pinning virtual threads
- 15:40Virtual threads pitfalls
- 18:31Structured concurrency
- 22:42Summary








