concurrency - Java - notify() vs notifyAll() - possible deadlock? -
is there situation in notify() can cause deadlock, notifyall() - never? for example, in case of multiple locks. notify() notifies 1 thread run, checks lock object , becomes waiting again, though thread unlock object. in case of using notifyall() , threads notified run , 1 of them in turn unlock object sure. yes. imagine implement producer - consumer problem synchronize, wait, , notify . (edit) in 2 producers , 2 consumers wait on same object monitor (end edit) .the producer calls notify in implementation. suppose have 2 threads running producer's code path. possible producer1 calls notify , wakes producer2. producer2 realizes can not work , subsequently fails call notify . deadlocked. (edit) had notifyall been called, both consumer1 , consumer2 have woken in addition producer2. 1 of consumers have consumed data , in turn called notifyall wake @ least 1 producer, allowing broken implementation limp along successfully. here reference question base scenario...