What Are Virtual Threads
Lightweight threads in Java 21.
Welcome to Virtual Threads
Virtual threads arrived as a final feature in Java 21 (JEP 444). They are lightweight threads managed by the JVM rather than the operating system.
The goal is simple: let you write straightforward thread-per-request code while still scaling to millions of concurrent tasks.
The Old Problem
A traditional platform thread maps one-to-one to an OS thread. Each one consumes around a megabyte of stack and is expensive to create.
That means you can only run a few thousand at once. Blocking I/O ties up an entire OS thread while it waits.
All lessons in this course
- What Are Virtual Threads
- Creating Virtual Threads
- Platform vs Virtual Threads
- Pitfalls: Pinning and ThreadLocals