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?
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 blow comment box.