What happens when wait() & notify() method are called

Upasana | December 04, 2019 | 1 min read | 13 views


wait() and notify() methods are called for inter thread communication on a shared object.

wait() method

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

  1. The calling thread gives up the lock.

  2. The calling thread gives up the CPU.

  3. The calling thread goes to the monitor’s waiting pool.

notify() method

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

  1. One of the waiting thread (may be a random thread) moves out of the monitor’s waiting pool.

  2. Thread comes into ready state (RUNNABLE).

  3. Tries its best to require the monitor lock before it can proceed to the method execution.


Top articles in this category:
  1. What is difference between sleep() and wait() method in Java?
  2. Can two threads call two different synchronized instance methods of an Object?
  3. What will happen if we don't synchronize getters/accessors of a shared mutable object in multi-threaded applications
  4. What is purpose of Collections.unmodifiableCollection
  5. What are four principles of OOP, How aggregation is different than Composition?
  6. can we write a java method that swaps two integers
  7. Troubleshooting Deadlock in Java

Recommended books for interview preparation:

Find more on this topic: