...
Code Block | ||
---|---|---|
| ||
//condition predicate is guarded by a lock on the shared object/variable synchronized (object) { while (<condition does not hold>) { object.wait(); } //proceed when condition holds } |
Likewise, if the await()
method of the {java.util.concurrent.locks.Condition}} interface is implemented, it should be enclosed in a loop.
Risk Assessment
To guarantee liveness and safety, the wait()
method should always be called inside a while
loop.
...