Platform threads and virtual threads
In the evolving landscape of Java concurrency, the role of threads takes center stage, influencing the performance and responsiveness of our applications. With the release of version 21, the Java platform introduces a groundbreaking paradigm shift – the coexistence of two distinct thread types, platform threads and the revolutionary virtual threads.
Traditionally, every instance of java.lang.Thread
in the JDK has been a platform thread. This thread type runs Java code on an underlying OS thread, monopolizing that thread for the entirety of the code’s execution. The number of platform threads is limited by the number of available OS threads, leading to potential bottlenecks in resource utilization.
Virtual threads mark a paradigmatic shift in the concurrency landscape. Unlike their platform counterparts, virtual threads run Java code on an underlying OS thread without capturing it for the code’s entire lifetime. It means...