Java 21 new feature: Virtual Threads #RoadTo21



Java 21 new feature: Virtual Threads #RoadTo21

Java 21 new feature: Virtual Threads #RoadTo21

Learn about Virtual Threads, how to use them and how they are working under the hood, a new feature brought to you by the JDK 21.

Virtual Threads are one of the most anticipated and exciting new feature of the JDK 21. They are a new model of threads, much lighter than the traditional platform threads. Virtual Threads are there to address the complexity and maintenance costs of asynchronous programming, without giving up on the performances this model gives. With virtual threads, you can get the best throughput performances with simple imperative blocking code. This episode tells you all about it: it shows you how you can use them, and how Virtual Threads are working under the hood.

⎯⎯⎯⎯⎯⎯ Chapters ⎯⎯⎯⎯⎯⎯

0:00 Intro
0:36 Why Virtual Threads have been added?
1:54 Analyzing the CPU usage of your blocking code
3:24 Why the “one request per thread” model cannot work
5:59 Solving this problem: less expensive threads or asynchronous code?
6:50 Introducing the asynchronous solution
9:36 Writing an imperative, blocking online shopping example
12:01 Making this code asynchronous the CompletableFuture API
13:49 Issues with the asynchronous code: debugging, testing, stack trace, exception handling, timeout handling
17:05 Making threads less expensive: by how much?
18:57 Creating and using virtual threads
22:50 How Virtual Threads are working under the hood
26:51 Running blocking code in a virtual thread
29:01 Handling native code and synchronized blocks: avoid pinning virtual threads
31:25 Wrapping up: virtual threads are cheap, blocking them is fine
33:01 Outro

⎯⎯⎯⎯⎯⎯ Resources ⎯⎯⎯⎯⎯⎯
◦ All the videos of the #RoadTo21 series: https://www.youtube.com/playlist?list=PLX8CzqL3ArzVHAHWowaXwYFlLk78D8RvL
◦ Upgrading from Java 17 to 21 #RoadTo21: https://youtu.be/5jIkRqBuSBs
◦ The JEP 444: Virtual Threads ➱ https://openjdk.org/jeps/444
◦ JDD 2018: Reactive programming: lessons learned by Tomasz Nurkiewicz ➱ https://youtu.be/5TJiTSWktLU
◦ Java Virtual Threads by Sergey Kuksenko ➱ https://inside.java/2023/05/04/levelup-loom/
◦ Helidon Níma & Virtual Threads by David Delabassee & Tomas Langer ➱ https://inside.java/2023/01/12/podcast-029/
◦ Java Asynchronous Programming Full Tutorial with Loom and Structured Concurrency ➱ https://youtu.be/2nOj8MKHvmw
◦ Launching 10 millions virtual threads with Loom ➱ https://youtu.be/UVoGE0GZZPI

#Java21 #Update #Java #OpenJDK #InsideJava #RoadTo21 #VirtualThread #Loom