Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Edited by sciSpider Java v3.0

...

Code Block
synchronized (object) {
  while (<condition&lt;condition does not hold>hold&gt;) {
    object.wait(); 
  }

  // Proceed when condition holds
}

...

Code Block
bgColor#FFcccc
synchronized(object) {
  if(<condition&lt;condition does not hold>hold&gt;)
    object.wait();
  //proceed when condition holds
}

...

Code Block
bgColor#ccccff
// Condition predicate is guarded by a lock on the shared object/variable
synchronized (object) {
  while (<condition&lt;condition does not hold>hold&gt;) {
    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      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;11. Concurrency (CON)      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CON32-J. Use notifyAll() instead of notify() to resume waiting threads