Virtual Threads: Taming the Wild Multithreading Beast
summary
Shows that Java 21 virtual threads let code create many cheap threads using startVirtualThread and newVirtualThreadPerTaskExecutor; a demo spawns 100,000 threads sleeping 1s to prove platform threads hit OOM while virtual threads survive. Benchmarks: virtual threads hit ~840 req/s on a no-delay endpoint vs ~38 for platform threads, but drop to ~547 vs 124 when each request forces unmounting, revealing mounting/unmounting overhead and pinning from synchronized or native calls. Structured concurrency scopes (shutdown-on-success/failure) simplify cancelling and joining child tasks.
AI-written summary · about
chapters (9)
- 0:00Introduction to virtual threads
- 5:14Virtual vs platform threads
- 7:27Creating virtual threads
- 11:30How virtual threads work
- 14:41When virtual threads fail
- 19:41Thread pinning issues
- 22:53Designing with virtual threads
- 26:26Structured concurrency
- 34:07Key takeaways and Q&A
related talks
38mIntroduction and pitfalls of Java's new concurrency model
45mIntroduction and pitfalls of virtual threads
41mIntroduction and pitfalls of Java's new concurrency model
38mIntroduction and pitfalls of Java's new concurrency model
37mMultiprocessing evolution & virtual threads in Java
53mVirtual Threads: Ushering in a New Era of Concurrency
51mIntroduction and Pitfalls of Java's New Concurrency Model
58mCreating Asynchronous Applications with Virtual Threads
