Introduction and pitfalls of Java's new concurrency model
summary
Java 19 introduces lightweight virtual threads and a virtual-thread-per-task Executor that let the JVM create hundreds of thousands of threads cheaply; demo creates 100,000 sleeping threads without OOM. Use the static startVirtualThread or the new executor and manage lifetimes with StructuredTaskScope (shutdownOnSuccess/shutdownOnFailure) to auto-cancel siblings. Pitfalls: blocking native or synchronized calls pin a virtual thread to its carrier, long CPU-bound work should not run on them, and thread pools aren’t the right limiter.
AI-written summary · about
chapters (11)
- 0:00Introduction to virtual threads
- 1:32Current Java concurrency model
- 6:52What are virtual threads
- 9:01Virtual threads demo
- 14:23How virtual threads work
- 17:36Pitfalls of virtual threads
- 19:02What is structured concurrency
- 22:57Structured concurrency demo
- 27:55Custom shutdown policies
- 31:25Benefits of structured concurrency
- 32:10Q&A session
related talks
38mIntroduction and pitfalls of Java's new concurrency model
38mIntroduction and pitfalls of Java's new concurrency model
51mIntroduction and Pitfalls of Java's New Concurrency Model
34mIntroduction and pitfalls of Java's new concurrency model
45mIntroduction and pitfalls of virtual threads
43mVirtual Threads: Taming the Wild Multithreading Beast
53mVirtual Threads: Ushering in a New Era of Concurrency
58mCreating Asynchronous Applications with Virtual Threads
