What happens when wait() & notify() method are called
Carvia Tech | 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
-
The calling thread gives up the lock.
-
The calling thread gives up the CPU.
-
The calling thread goes to the monitor’s waiting pool.
notify() method
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
- Troubleshooting Deadlock in Java
Find more on this topic:
Subscribe to Interview Questions
Recommended books for interview preparation:
Book you may be interested in..
Book you may be interested in..
Similar Posts
- Code review checklist for Java developers
- Count word frequency in Java
- Secure OTP generation in Java
- HmacSHA256 Signature in Java
- Submit Form with Java 11 HttpClient - Kotlin
- Java Exception Class Hierarchy
- Http download using Java NIO FileChannel
- CRC32 checksum calculation Java NIO
- Precision and scale for a Double in java
- Difference between HashMap, LinkedHashMap and TreeMap