Introduction and pitfalls of virtual threads
summary
Java 21 adds virtual threads and structured concurrency and demonstrates that thousands scale: the demo creates 10,000 virtual threads demo on a laptop and benchmark shows 100,000 virtual threads ≈225MB where platform threads ran out of memory. Details cover carrier threads, mounting/unmounting stacks, pinning pitfalls (synchronized, JNI, certain file ops), a virtual-thread-per-task executor, run flags to detect pinning, and a custom StructuredTaskScope that cancels remaining tasks when a product <100 is found, which works as shown.
AI-written summary · about
chapters (13)
- 0:00Introduction to virtual threads
- 1:57Platform threads explained
- 4:28Limitations of platform threads
- 7:17Virtual threads introduction
- 10:12Creating virtual threads demo
- 13:44Scaling virtual threads demo
- 14:48How virtual threads work
- 18:21Pitfalls of virtual threads
- 21:09Structured concurrency explained
- 25:22Structured concurrency demo
- 29:37Custom structured concurrency
- 33:12Virtual threads takeaways
- 33:34Q&A session
related talks
38mIntroduction and pitfalls of Java's new concurrency model
51mIntroduction and Pitfalls of Java's New Concurrency Model
38mIntroduction and pitfalls of Java's new concurrency model
41mIntroduction and pitfalls of Java's new concurrency model
43mVirtual Threads: Taming the Wild Multithreading Beast
34mIntroduction and pitfalls of Java's new concurrency model
50mVirtual Threads, Structured Concurrency, Extent Locals: When to Use Them & How
53mVirtual Threads: Ushering in a New Era of Concurrency
