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.
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 require the monitor lock before it can proceed to the method execution.
Top articles in this category:
- What is difference between sleep() and wait() method in Java?
- Can two threads call two different synchronized instance methods of an Object?
- What will happen if we don't synchronize getters/accessors of a shared mutable object in multi-threaded applications
- What is purpose of Collections.unmodifiableCollection
- What are four principles of OOP, How aggregation is different than Composition?
- can we write a java method that swaps two integers
- What is difference between ExecutorService submit and execute method