0

How the Object.notify() method works

I read some articles but still confusion. Can someone explain how it works and with example.

26th Aug 2020, 3:03 PM
Naveen Surya
Naveen Surya - avatar
2 Antworten
+ 4
Naveen Surya The notify() method is defined in Object class which is the super most class in Java. It is used to wakes up only one thread that is waiting on the object and that thread starts execution. Suppose there are multiple threads that are waiting for an object, then it will wake up only one of them. Only one thread gets the notification and the remaining thread have to wait for further notification. It is a final method, so we can’t override it. 1. It totally depends on the OS implementation of thread management. This method wakes up only one thread that called wait() method on the same object. 2. The awakened thread will not be able to proceed further until the current thread gives the lock on this object. 3. It does not actually give up a lock on a resource. It just tells the waiting thread that it can wake up. 4. The awakened thread will compete in the usual manner with any other threads that might be actively competing to synchronize on this object. https://javagoal.com/notify-method-in-java/
28th Aug 2020, 1:29 AM
Raina Dhankhar
Raina Dhankhar - avatar
0
some example but a little more complex https://code.sololearn.com/crlPnyLILPE1/#
10th Sep 2020, 5:19 PM
zemiak