We can use notify()
to give the notification for only one waiting Thread. If multiple Threads are waiting then only one Thread will be notified and the remaining Thread will keep waiting for further information. We can not expect which Thread will be notified if multiple Threads are waiting it depends on JVM.
We can use notifyAll()
to give the notification for all waiting Threads of a particular object even though multiple Threads are notified but execution will be performed one by one because Threads require a lock and only one lock is available.
Note- On which object we are calling wait()
, Thread required a lock of that particular object for example when calling wait()
on object1 then we have to get the lock of object1
Similar Java Tutorials
- Odd Even in Java
- Method to print exception information in Java
- Exception Handling by Using try-catch in Java
- Checked Exception vs Unchecked Exception
- Exception Hierarchy in Java
- Java Exception Handling Interview Questions
- final finally finalize in java
- User Defined Exception in Java
- Exception Handling Keyword in Java
- throw throws in Java
- try with multiple catch block in Java
- Threads in Java
- Thread priority in Java
- Threads communication in Java