</>CodexBash
All articles
Java and Spring

Virtual threads

Java's virtual threads in depth: why platform threads limit servers, how virtual threads mount and unmount on carrier threads, creating them, what they speed up and what they do not, pinning and how Java 24 reduced it, ThreadLocal and pooling pitfalls, limiting concurrency, and using them in Spring Boot.

CodexBash, , 6 min read

For most of Java's history, each Java thread was a thin wrapper around an operating system thread. That made threads expensive: each one reserves memory for its stack and costs the OS scheduling work, so a server could run a few thousand at most. Web servers that handled one request per thread hit that ceiling under load, which pushed developers toward complex asynchronous, reactive code. Virtual threads, final in Java 21, remove the ceiling: they are so cheap you can create millions, letting simple, blocking, one-thread-per-request code scale like asynchronous code. Our multithreading article introduced them; this one explains how they work and how to use them well.

Sign in to read the rest

The whole 6 minute article is free with an account, along with every problem, lesson and tutorial. No card.