Replies: 1 comment 1 reply
-
I am not the maintainer of this repository but I will still try to explain it from my perspective. The big advantage of virtual threads is that the platform threads can be reused for other tasks (other virtual threads) while some task in blocking/waiting on something like I/O. They allow for higher CPU utilization when only a tiny part of the fraction of the time spent by threads is actually CPU time (when the threads are waiting for the majority of their lifetime). for(int i=0;i<10;i++){
Thread.startVirtualThread(()->{while(true);});//use up the carrier threads
}
Thread.startVirtualThread(()->System.out.println("Hi")); If I run this on my system (configured with less than 10 carrier threads), I don't get any output. On the other hand, the OS scheduler is made for pausing threads that are doing CPU work and allowing other threads to execute. |
Beta Was this translation helpful? Give feedback.
-
I was revisiting the JugBD session on JDK21 vThreads, and the question popped in my mind to know in greater details about the problems that we can encounter, or in other words, the limitations of vThreads while using for CPU intensive tasks. Can you please share with greater details, please?
Beta Was this translation helpful? Give feedback.
All reactions