Thread ~ 10.000 Threads max 1 ms creation time 1 KB per Thread 1.000.000+ Threads possible Created in 1 μs 1000 x 100 x 1000 x Platform Thread Virtual Thread Impact https://docs.oracle.com/en/java/javase/21/core/virtual-threads.html https://www.infoq.com/articles/java-virtual-threads-a-case-study/ https://github.com/ebarlas/java-httpserver-vthreads
• High concurrency >1000 concurrent tasks • Request-per-thread model Great us if When to Use Virtual Threads • CPU-intensive calculations • Thread pools (NEVER pool Virtual Threads!) Avoid for
Save • Copy per (virtual) Thread • Slower due to Implementation ThreadLocal What about ThreadLocal • Immutable Data • Memory Save • Designed for Virtual Threads • Efficient Implementation ScopedValue
(Final seit Java 21) → migrate if I/O-bound workloads 2. Scoped Values (Final in Java 25) → ThreadLocal replace where immutable, use recipe 3. Structured Concurrency (Fifth Preview) → experiment and feedback; not in prod, yet 4. Stable Values (Preview in Java 25) → Check for lazy initialization
immutable context A million Virtual Threads is fine! NEVER pool Virtual Threads No ThreadLocals with Virtual Threads Not for CPU-intensive Tasks Pro tip: Use a recipe to Understand surface