next thread which will run a synchronized blocked method
posted 8 years ago
Simple question: Imagine I have a synchronized method in a class, and a thread has blocked it. There are 4 threads waiting to use that method, after it returns. Upon the method return, which thread will get it first? The first thread that was waiting, or there is no guaranteed order?
The behavior of favoring the longest waiting thread while giving lock acquisition is called fairness. This is not supported by java monitor locks, however, the java concurrent util libraries provide ReentrantLocks and other utilities that provides an optional support for fairness. There are a few fine prints that you must see in the javadocs before using it [ June 09, 2008: Message edited by: Nitesh Kant ]