...
This compliant solution uses the notifyAll()
method which sends notifications to all threads that wait on the same object. As a result, liveness is not affected unlike the noncompliant code example. The condition predicate controls which threads can resume their operations. Ensure that the lock is released promptly after the call to notifyAll()
. This is not a requirement in this particular example because it is a producer-consumer process.
Code Block | ||
---|---|---|
| ||
else if(number == 3) { Thread.sleep(2000); list.notifyAll(); } |
...