What determines which of the two competing threads gets a lock?

When two threads try to get a lock on the same object, what things are thought to determine which thread the lock should be passed to.

+5
source share
2 answers

According to Java documentation for notification () :

Wakes up one thread waiting for this object monitor. If any threads are waiting on this object, one of them is selected wakes up. The choice is arbitrary and is at the discretion of the implementation. . On the object monitor, a thread is waiting, calling one of the wait methods.

, synchronized(obj){}, , obj, . .

(.. , , ), ReentrantLock: , , .

+4

Java Oracle Docs:

. true, . - .

, FIFO (First-in-First-out), ( ).

0

All Articles