DEV Community

Alexander Holbreich
Alexander Holbreich

Posted on

JDK 21 : Virtual Threads intro

Java has regarded platform threads as lightweight abstractions built upon operating system (OS) threads (see drawing below). The creation of these platform threads incurred a significant cost due to the allocation of resources at the OS level (kernel). To mitigate this overhead, in Java, we traditionally used thread pools. Furthermore, it’s necessary to place constraints on the number of platform threads since these resource-intensive threads can potentially impact the overall machine performance. In effect Java is not itself managing the state of these threads, it rather relies on the OS in this regard with all the pros and cons. On one side Java doesn’t need to manage scheduling and blocking. On the other side of this, the java process becomes dependent on the OS scheduling, handling of blocking I/O etc and cannot really make any assumption here. Also, the scheduling algorithms would differ from OS to OS.

Those limitations are grounded in the fact that platform threads are directly mapped on a one-to-one basis to OS threads.

Read the whole article
JDK 21 : Virtual Threads

Top comments (0)