Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: edits

...

This noncompliant code example declares a nonvolatile non-volatile Boolean flag.

Code Block
bgColor#FFCCCC
private Boolean done;
while (!this.done) {
  Thread.sleep(1000);
}

...

The volatile flag establishes a happens-before relation between this thread and any other thread that sets done and this thread.

Risk Assessment

Relying on the synchronization semantics of Thread.class Thread's sleep(), yield() and Thread.sleepgetState() methods for synchronization control can cause unexpected behavior.

...