...
This noncompliant code example declares a nonvolatile non-volatile Boolean
flag.
Code Block | ||
---|---|---|
| ||
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.
...