Say I have three threads, thread 1, thread 2, and thread 3 all sharing the same lock. Thread 2 acquires the lock, does some work and then blocks via a call to the await method. Thread 1 then acquires the lock, does some work, and during the middle of it, thread 3 tries to acquire the lock but is blocked since thread 1 is holding it. Thread 1 finishes working and, before terminating, signals thread 2 that it can reacquire the lock. So what happens then? Will thread 2 or thread 3 acquire the lock next?
Thank you so much for your time and help in advance.
nofity()
ornotifyAll()
is called, there is no provision to specify which waiting thread will obtain the lock. So in your example, Thread 2 or Thread 3 could get the next lock. docs.oracle.com/javase/8/docs/api/java/lang/… – anonymous