
Virtual Threads in Java 21: The End of the Scarcity Era (and the Pitfalls That Can Take You Down)
Series: Java in Real Production — This is the first of two articles. Here we cover the fundamentals, the right mental model, and the two pitfalls that silently bring down applications. In the second, we go deeper into Docker, Kubernetes, and observability with JFR. Imagine a fine-dining restaurant. Every table — an HTTP request — needs a dedicated waiter. The waiter takes the order, walks to the kitchen... and just stands there, waiting for the chef to finish the dish . Meanwhile, new tables keep arriving. But there are no waiters available. The maître d' starts turning customers away at the door. The restaurant is full of waiters standing idle in the kitchen — and the dining room is empty of service. This is the classic Platform Threads model in Java. Each thread consumes roughly 1MB of stack in the operating system. On a server with 4GB dedicated to threads, you get at most ~4,000 waiters. Sounds like a lot? For a modern application with heavy I/O — database calls, external HTTP, mes
Continue reading on Dev.to
Opens in a new tab


