Java’s notifyAll() awakens all threads waiting on an object’s monitor. Those threads can then compete to reacquire the monitor and continue. section 7.3
Use it inside synchronized code after changing shared state. In a bounded producer-consumer list, a consumer notifies waiting producers after removing a value, while a producer notifies waiting consumers after adding one. section 7.3
Bounded shared list
The consumer removes a value and calls Main.list.notifyAll(); when the list is empty, it calls Main.list.wait(). The producer follows the inverse pattern: it adds a value and calls notifyAll(), or waits when the list reaches 100 values.
