Concurrency beginner

Virtual threads

Create millions of lightweight virtual threads instead of heavy OS threads.

✕ Java 8
Thread thread = new Thread(() -> {
    System.out.println("hello");
});
thread.start();
thread.join();
✓ Java 21+
Thread.startVirtualThread(() -> {
    System.out.println("hello");
}).join();

Lightweight

Virtual threads use KB of memory, platform threads use MB.

♾️

Scalable

Create millions of threads — no pool sizing needed.

🧹

Simple model

Write blocking code that scales like async code.

Old Approach
Platform Threads
Modern Approach
Virtual Threads
Since JDK
21
Difficulty
beginner
Virtual threads
Available

Widely available since JDK 21 LTS (Sept 2023)

How it works

Virtual threads are lightweight threads managed by the JVM, not the OS. You can create millions of them without tuning thread pools. They're ideal for I/O-bound tasks like HTTP calls and database queries.

Share 𝕏 🦋 in