Introduction and pitfalls of Java's new concurrency model
summary
Java introduces virtual threads (preview in Java 20, available to try in Java 21) as lightweight JVM‑managed threads that let an application create 10,000 virtual threads on a laptop where platform threads OOM, because stacks live on the heap and resize. New APIs include Thread.startVirtualThread and Executors.newVirtualThreadPerTaskExecutor, and structured concurrency via StructuredTaskScope with policies like shutdownOnSuccess and shutdownOnFailure. Demos show mounting/unmounting on carrier (platform) threads, pinning for synchronized/native I/O, pitfalls for CPU‑bound work and legacy libraries, and a custom scope that cancels remaining searches when a cheap match is found.
AI-written summary · about
chapters (12)
- 0:00Java's new concurrency model intro
- 2:14Current Java concurrency limits
- 8:45Virtual threads explained
- 12:20Creating virtual threads
- 16:43Scaling with virtual threads
- 17:26Virtual thread scheduling
- 20:17Pitfalls of virtual threads
- 22:03Structured concurrency intro
- 26:21Using structured concurrency
- 31:23Custom concurrency policies
- 35:18Virtual threads best practices
- 36:20Q&A
related talks
51mIntroduction and Pitfalls of Java's New Concurrency Model
41mIntroduction and pitfalls of Java's new concurrency model
38mIntroduction 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
49mEven threads are now virtual:past, present, future of concurrency in Java.
