Often, one thread is producing some data, while another thread wants to use it. |
A flag variable is introduced that both threads can check. |
If the data is not ready (flag is false), the consuming thread can call the method wait ( ), which causes it to be suspended until some other event occurs. |
When the producing thread has some data, it can set the flag to be true and call the method notify ( ), which causes an event that will "wake up" one of the suspended threads. |
If the user doesn't get the logic right, there are possibilities for deadlock or other forms of non-progress. |