Virtual Threads, Structured Concurrency, Extent Locals: When to Use Them & How
summary
Virtual threads run on platform carrier threads so blocking calls become cheap and throughput jumps — a 1,000-sleep request demo finishes in ~1s on virtual threads versus batched ~200-worker platform threads; memory drops (example: ~64MB vs ~1.9GB) but heap GC increases because suspended stacks land on the heap. Use Java Flight Recorder / Java Mission Control / jcmd / JConsole to observe pinning (synchronized pinning affects Java ≤23, fixed in Java 24), rate-limit external calls with semaphores, avoid virtual threads for CPU-bound tasks, and try structured concurrency (Structured Task Scope in Java 25 preview) and scoped values where inheritable context matters.
AI-written summary · about
chapters (12)
- 0:00Introduction to virtual threads
- 3:28Scoped values and concurrency
- 8:11Benefits and use cases
- 11:35Implementation and demo
- 16:25Throughput and performance
- 20:31Monitoring and memory impact
- 25:35Resource management
- 28:49Pinning and blocking behavior
- 32:15File I/O considerations
- 33:55Virtual threads vs reactive
- 36:24Thread locals and conclusion
- 43:23Q&A session
related talks
45mIntroduction and pitfalls of virtual threads
38mIntroduction and pitfalls of Java's new concurrency model
43mVirtual Threads: Taming the Wild Multithreading Beast
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
53mVirtual Threads: Ushering in a New Era of Concurrency
37mMultiprocessing evolution & virtual threads in Java
