vavr icon indicating copy to clipboard operation
vavr copied to clipboard

Avoid synchronized block or methods

Open reda-alaoui opened this issue 1 year ago • 2 comments

According to https://docs.oracle.com/en/java/javase/21/core/virtual-threads.html#GUID-04C03FFC-066D-4857-85B9-E5A27A875AF9:

A current limitation of the implementation of virtual threads is that performing a blocking operation while inside a synchronized block or method causes the JDK's virtual thread scheduler to block a precious OS thread, whereas it wouldn't if the blocking operation were done outside of a synchronized block or method. We call that situation "pinning".

IMHO, all synchronizd blocks or methods should be replaced with ReentrantLock usage.

reda-alaoui avatar Jan 31 '24 15:01 reda-alaoui

Not all, only io bound I think.

He-Pin avatar Jan 31 '24 16:01 He-Pin

This is a temporary limitation of Virtual Threads and applies only to blocking operations inside synchronized blocks. I went through all cases of synchronized, and only deprecated-for-removal Lazy can run blocking code inside it, and that's the only change needed here I believe

pivovarit avatar Aug 21 '24 09:08 pivovarit