[java] Java: notify() vs. notifyAll() all over again

When you call the wait() of the "object"(expecting the object lock is acquired),intern this will release the lock on that object and help's the other threads to have lock on this "object", in this scenario there will be more than 1 thread waiting for the "resource/object"(considering the other threads also issued the wait on the same above object and down the way there will be a thread that fill the resource/object and invokes notify/notifyAll).

Here when you issue the notify of the same object(from the same/other side of the process/code),this will release a blocked and waiting single thread (not all the waiting threads -- this released thread will be picked by JVM Thread Scheduler and all the lock obtaining process on the object is same as regular).

If you have Only one thread that will be sharing/working on this object , it is ok to use the notify() method alone in your wait-notify implementation.

if you are in situation where more than one thread read's and writes on resources/object based on your business logic,then you should go for notifyAll()

now i am looking how exactly the jvm is identifying and breaking the waiting thread when we issue notify() on a object ...