<qhelp>

<overview>

The methods `notify`, `notifyAll`, and `wait` should only be called by a thread that is the owner of the object's monitor (intrinsic lock). In other words, the methods should only be called from within a synchronized statement or method. Otherwise the method call will throw `IllegalMonitorStateException`.

</overview> <recommendation>

Ensure that calls to `notify`, `notifyAll`, or `wait` are called from within a synchronized statement or method.

</recommendation> <example>

In the following example, the methods `produce` and `consume` use `wait` and `notifyAll` to communicate. However, the `consume` method is not synchronized, so the calls to `wait` and `notifyAll` will always throw an exception.

To fix this example, add the `synchronized` keyword to the declaration of the `consume` method.

</example> <references>

- J. Bloch. Effective Java (second edition), p. 276. Addison-Wesley, 2008.
- Java API Documentation: notify(), notifyAll(), wait(), wait(long).
</references> </qhelp>