Introduction and pitfalls of Java's new concurrency model
Stop writing complex reactive code. Java's virtual threads bring back a simple, scalable thread-per-request model that makes blocking I/O cheap again.
#1about 7 minutes
Understanding Java's traditional platform threads
Traditional platform threads are resource-intensive because they map directly to OS threads, leading to memory limitations and the need for pooling with executor services.
#2about 2 minutes
Introducing lightweight virtual threads in Java 21
Virtual threads are a lightweight, JVM-managed alternative to platform threads that avoid expensive OS calls and use resizable heap memory for their stacks.
#3about 2 minutes
Comparing memory usage of platform vs virtual threads
A comparison shows that while memory usage is similar for a small number of threads, virtual threads use significantly less memory at scale, avoiding out-of-memory errors.
#4about 5 minutes
How to create and manage virtual threads
Virtual threads can be created using the Thread.startVirtualThread() static method, a builder pattern, or the new newVirtualThreadPerTaskExecutor which simplifies lifetime management.
#5about 5 minutes
How virtual threads work with carrier threads
Virtual threads run on a pool of platform threads called carrier threads, and are mounted or unmounted during blocking operations to keep the carrier threads busy.
#6about 2 minutes
Common pitfalls when using virtual threads
Avoid common pitfalls such as expecting faster single-thread performance, using them for long-running CPU-bound tasks, or pooling them, as they are designed to be cheap and disposable.
#7about 6 minutes
The problem structured concurrency solves
Unlike unstructured concurrency which can lead to leaked threads and wasted resources, structured concurrency ensures the lifetime of child threads is confined to a specific code block.
#8about 4 minutes
Implementing a race policy with ShutdownOnSuccess
The ShutdownOnSuccess policy in StructuredTaskScope is used to race multiple tasks and retrieve the result of the first one that completes successfully, canceling the others.
#9about 3 minutes
Implementing an all-or-nothing policy with ShutdownOnFailure
The ShutdownOnFailure policy ensures that all forked tasks must complete successfully; if any task fails, all other running tasks are immediately canceled.
#10about 6 minutes
Creating a custom structured task scope policy
Developers can extend StructuredTaskScope and override the handleComplete method to implement custom shutdown logic based on specific business criteria from task results.
#11about 1 minute
Key takeaways for adopting virtual threads
To get started, developers primarily need to use Thread.startVirtualThread() for single tasks or the newVirtualThreadPerTaskExecutor for managing multiple tasks.
#12about 9 minutes
Q&A on virtual threads, reactive programming, and Java 21
The speaker answers audience questions about replacing Project Reactor, migrating existing applications, using thread-locals, and other new features in Java 21.
Related jobs
Jobs that call for the skills explored in this talk.
Matching moments
03:59 MIN
Understanding the new virtual threads model
Modern Java: This is not your father's Java anymore
07:13 MIN
How virtual threads solve the concurrency problem
Java 21: The Revolution of Virtual Threads - A Deep Dive
02:05 MIN
Understanding the goals of Java's Project Loom
Java's Project Loom & Co - the end for reactive programming?
02:24 MIN
Solving blocking issues with Project Loom's virtual threads
Java's Project Loom & Co - the end for reactive programming?
01:12 MIN
Comparing Project Loom with reactive programming
Kubernetes Native Java
03:16 MIN
What's new in the Java 21 LTS release
Beam Me Up, Java! Unraveling the Warp-Speed Evolution: A Journey through Java LTS Versions 11 to 21
01:32 MIN
Conclusion on Project Loom's impact on reactive programming
Java's Project Loom & Co - the end for reactive programming?
02:57 MIN
Understanding the problem of blocked threads in concurrency
Java's Project Loom & Co - the end for reactive programming?
The Concept of Concurrency & Multithreading: What Are They And How They FunctionAs the world around us moves ever more online, the need for software engineers is growing - seemingly by the hour. Whether by building firewalls that fend off the next big data breach, or developing the next app that goes viral, we have a seemingly i...
Benedikt Bischof
Using Java 17 latest features in real world projectsWelcome to this issue of the WeAreDevelopers Live Talk series. This article recaps an interesting talk by Ron Veen who introduced the audience to some of the most interesting features that got added to the Java language.About the speaker:Ron is a hig...
Chris Heilmann
WeAreDevelopers LIVE days are changing - get ready to take partStarting with this week's Web Dev Day edition of WeAreDevelopers LIVE Days, we changed the the way we run these online conferences. The main differences are:Shorter talks (half an hour tops)More interaction in Q&AA tips and tricks "Did you know" sect...
Chris Heilmann
All the videos of Halfstack London 2024!Last month was Halfstack London, a conference about the web, JavaScript and half a dozen other things. We were there to deliver a talk, but also to record all the sessions and we're happy to share them with you. It took a bit as we had to wait for th...
From learning to earning
Jobs that call for the skills explored in this talk.