Class Central is learner-supported. When you buy through links on our site, we may earn an affiliate commission.

YouTube

Java 21 New Feature - Virtual Threads

Java via YouTube

Overview

Explore Virtual Threads, a groundbreaking feature in JDK 21, in this 34-minute video tutorial. Discover how to implement and leverage Virtual Threads to address the complexities of asynchronous programming while maintaining high performance. Learn why traditional "one request per thread" models fall short and how Virtual Threads offer a solution. Follow along with practical examples, including an online shopping scenario, to understand the differences between blocking code, asynchronous programming with CompletableFuture API, and the simplicity of Virtual Threads. Gain insights into the inner workings of Virtual Threads, their creation and usage, and best practices for handling native code and synchronized blocks. By the end of this comprehensive guide, grasp why Virtual Threads are considered a game-changer in Java concurrency, offering the benefits of simple imperative blocking code without sacrificing throughput performance.

Syllabus

Intro
Why Virtual Threads have been added?
Analyzing the CPU usage of your blocking code
Why the "one request per thread" model cannot work
Solving this problem: less expensive threads or asynchronous code?
Introducing the asynchronous solution
Writing an imperative, blocking online shopping example
Making this code asynchronous the CompletableFuture API
Issues with the asynchronous code: debugging, testing, stack trace, exception handling, timeout handling
Making threads less expensive: by how much?
Creating and using virtual threads
How Virtual Threads are working under the hood
Running blocking code in a virtual thread
Handling native code and synchronized blocks: avoid pinning virtual threads
Wrapping up: virtual threads are cheap, blocking them is fine
Outro

Taught by

Java

Reviews

Start your review of Java 21 New Feature - Virtual Threads

Never Stop Learning.

Get personalized course recommendations, track subjects and courses with reminders, and more.

Someone learning on their laptop while sitting on the floor.