A lot of open-source projects are trying to get away from using syncrhonized
due to its behavior with Virtual Thread.
Regarding Virtual Threads, I understand that within a synchronized
block, in situations where network communication (which would normally be asynchronous) or file I/O occurs, the Carrier Thread should ideally be handed over to another thread, but it remains “pinned.” Is my understanding correct?
Is the situation different with traditional ThreadPool-based multithreading? In cases where asynchronous processing occurs within a synchronized
block, can the Carrier Thread be properly handed over to another thread?
Additionally, does a similar issue occur during the process of acquiring a Lock
to execute a synchronized
block? In other words, when another thread is executing a synchronized
block and the Virtual Thread is waiting, does it remain pinned until the lock is released?
My questions could be summarized as below:
public void someMethod() {
// Does Virtual Thread get pinned here, too?
synchronized(this) {
someAsyncIOMethods() // Virtual Thread gets 'pinned' here, right? How about classical ThreadPools?
}
}