...
| Code Block |
|---|
synchronized (object) {
while (<condition<condition does not hold>hold>) {
object.wait();
}
// Proceed when condition holds
}
|
...
| Code Block | ||
|---|---|---|
| ||
synchronized(object) {
if(<condition<condition does not hold>hold>)
object.wait();
//proceed when condition holds
}
|
...
| Code Block | ||
|---|---|---|
| ||
// Condition predicate is guarded by a lock on the shared object/variable
synchronized (object) {
while (<condition<condition does not hold>hold>) {
object.wait();
}
// Proceed when condition holds
}
|
...
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
References
| Wiki Markup |
|---|
\[[API 06|AA. Java References#API 06]\] [Class Object|http://java.sun.com/javase/6/docs/api/java/lang/Object.html] \[[Bloch 01|AA. Java References#Bloch 01]\] Item 50: Never invoke wait outside a loop \[[Lea 00|AA. Java References#Lea 00]\] 3.2.2 Monitor Mechanics, 1.3.2 Liveness \[[Goetz 06|AA. Java References#Goetz 06]\] Section 14.2, Using Condition Queues |
...
CON30-J. Synchronize access to shared mutable variables 11. Concurrency (CON) CON32-J. Use notifyAll() instead of notify() to resume waiting threads