notify VS notifyAll
Hi
I could not find when notifyAll fits in the concurrency maze. Say n threads are in the wait pool on an object, then notify and notifyall will have same effect, as ultimatly only one thread will actually accuire a lock and the rest will move to waiting state.
Can any one tell me what i am missing here?
Thanks
Ashish
> Hi
>
> I could not find when notifyAll fits in the
> concurrency maze. Say n threads are in the wait pool
> on an object, then notify and notifyall will have
> same effect,
No, they won't. Read the docs carefully.
> as ultimatly only one thread will
> actually accuire a lock and the rest will move to
> waiting state.
>
> Can any one tell me what i am missing here?
Only one thread at a time will ge the lock. With notifyAll, ALL threads are awakened and all get in line to get the lock. One gets it, and when he's done, the next one gets it, etc.
With notify, only one thread even has a chance to get it, and when he's done, the other threads are still left wait()ing.
jverda at 2007-7-29 16:11:29 >
