Using wait() and notify() methods:
wait()– Causes the current thread to wait until another thread invokes the
notify()method or thenotifyAll()method for this object.
notify()– Wakes up a single thread that is waiting on this object’s monitor.