Junior — Middle
Can you explain the purpose of the notifyAll method in Java?
sobes.tech AI
Answer from AI
The notifyAll() method in Java is used to wake up all threads that are waiting on an object's monitor (i.e., have called wait() on that object). Unlike notify(), which wakes up only one random waiting thread, notifyAll() wakes up all of them, allowing them to attempt to re-acquire the monitor and continue execution. This is useful when multiple threads might be blocked and need to be awakened so they can check the condition to continue working.