Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1
notify() wakes up only a random thread, while notifyAll() wakes up all waiting threads. It really depends on how you program your running threads. Imagine you have 3 threads: a, b and c. a is performing some task, and you call a.wait() in b and c. When a finishes you can call notifyAll(), so b and c start running next instruction after a.wait(), or notify(), this will wake up only b or only c. The other will wait until next time a calls notify() again. * If a does not call notify() again, one of b or c will be waiting forever. * If b wakes up and calls a.wait() again, it can be notified next time, so c won't. c may not be awaken ever.
28th Nov 2016, 11:01 AM
Pascu LA
Pascu LA - avatar