Java 21 Virtual Threads Bring Lightweight Concurrency to JVM at Scale
Java 21 formally introduced virtual threads as a stable feature under JEP 444, fundamentally altering how concurrency is handled on the JVM. Unlike traditional platform threads, which wrap OS threads and consume roughly 1MB of stack memory each, virtual threads are managed by the JVM itself and run on a small pool of carrier threads. When a virtual thread blocks on I/O, the JVM detaches it from its carrier thread, freeing resources for other tasks and enabling far greater scalability. Spring Boot 3.2 supports virtual threads with a single configuration change, allowing frameworks like Tomcat to handle each request on a virtual thread without exhausting thread pools. Developers are advised to avoid pooling virtual threads and to prefer ReentrantLock over synchronized blocks, as the latter can cause threads to remain pinned to their carriers during blocking calls.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in