-->

A Simple Wait / Notify in Java

16 2019
  • Create a object called “lock”.
private Object lock = new Object();
  • Call the wait() where you want to stop the code.
synchronized (lock)
{
    lock.wait();
}
  • Call the notify() in somewhere else in the code to proceed to the next line of wait().
synchronized (lock) {
lock.notify();
}

Leave a Reply