For example, one thread read data from a buffer and one thread write data into buffer. The reading data thread needs to wait until the writing data thread completely write a block data into the buffer. The writing data thread needs to wait until the reading data thread completely read the data from the buffer. If wait(), notify(), and notifyAll() methods can be called by a ordinary method , the reading thread calls wait() and the thread is being added to waiting queue . At just the same moment, the writing thread calls notify() to signal the condition changes. The reading thread misses the change and waits forever. Hence, they must be called inside a synchronized method or block which is mutually exclusive.



