We must have seen or hear about the statement “The awakened threads will not be able to proceed until the current thread relinquishes the lock on this object “, let’s discuss this statement in detail.

This statement is generally used when we are working with wait() and notify() methods.

Wait() method causes the current thread to wait until another thread invokes the notify() or notifyAll() method for this object.

Now, as soon as notify() or notifyall() method is called it notifies the waiting thread, but object monitor is not yet available. Object monitor is available only when thread exits synchronized block or synchronized method. So, what happens is code after notify() is also executed and execution is done until we reach end of synchronized block.

In below program, following statement was below notify() and it was executed.

System.out.println("Notify() has been called, Thread-2 have been notified and "

+ "Thread-1 is about to release object lock");

Program >

class MyRunnable1 implements Runnable{

@Override

publicvoid run(){

synchronized (this) {

try{

System.out.println("Thread-1 is sleeping...");

Thread.sleep(1000);

}catch(InterruptedException e){e.printStackTrace();}

this.notify(); //It will notify waiting threads, but object lock is yet to be release

System.out.println("Notify() has been called, Thread-2 have been notified and"