I came across Java: notify() vs. notifyAll() all over again but still could not satisy myself.
xagyg explained it very well but in the end it became very complex to memorize the concept.
I am trying my best here with simple daily life example so that i and others can come back to this if any one forget. My source of understanding is answer by xagyg in above link but trying to simplyfy the things here.
Say two guys go to movie theatre and found its houseful. But then box office guy say Jon told them there is a ticket that has been reserved for president. If he does not come, he will sell it off. Then guys told to jon, ok we are waiting in hotel near by, please notify us when you get any info. These guys go to hotel and sleep. Now president does not turn up, now Jon has two options First is notify one of the guy and let other sleep. If he does that one can go movie while other will probably continue to sleep(till he doesn't get notified. I am assuming this guy didn't have sleep for a year :)). Another option is he notifies(awakens) both of them, choose any one of them(In actual java example program does not select but its vm/thread scheduler) for movie.In that case he will keep other guy in hotel room as he can create some kind of issues :(. Now once the show ends, this guy can go for next show if ticket is available. Consider ticket as lock, theatre as object. This what exactly notify and notifyAll does. So it is clear that notifAll is better over notify when in confusion
Now consider producer/consumer example.
say two consumer thread are waiting for production in store. Now what producer does, he produces two items in single go and exit. Now if producer use notify, only one thread can consumer while other will continue to wait for forever.
But if producer uses notifyAll() here, both thread can go for consumption one at a time
Let me know if my understanding is correct?