What happens when wait() & notify() methods are called?

By | August 12, 2019

In this blog post we will discuss about one of the very important java interview question What happens when wait() & notify() methods are called? 

When wait() method is invoked from a synchronized context, the following things happen

  • The calling thread gives up the lock.
  • The calling thread gives up the CPU.
  • The calling thread goes to the monitor’s waiting pool.

And in case of notify() method, following things happen

  • One of the waiting thread (may be a random thread) moves out of the monitor’s waiting pool.
  • Thread comes into ready state (RUNNABLE).
  • Tries its best to acquire the monitor lock before it can proceed to the method execution.

 

You may also like:

What are common multi-threading issues faced by Java Developers?
What are different states of a Thread? What does those states tell us?
What is difference between sleep(), yield() and wait() method?
What is difference between Callable and Runnable Interface?
What is difference between intrinsic synchronization and explicit locking using Lock?
What will happen when an exception arises from within a synchronized code block? Will lock be retained or released?
What is difference between Executor submit() and execute() method?

That’s all about  What happens when wait() & notify() methods are called?
If you have any feedback or suggestion please feel free to drop in below comment box.

Leave a Reply

Your email address will not be published.