1 | Often, one thread is producing some data, while another thread wants to use it. |
2 | A flag variable is introduce that both threads can check. |
3 | 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. |
4 | 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. |
5 | If the user doesn't get the logic right, there are possibilities for deadlock or other forms of non-progress. |