...
Code Block |
---|
public void consumeElement() throws InterruptedException {
synchronized (vector) {
while (vector.isEmpty()) {
vector.wait();
}
// Consume when condition holds
}
}
|
...
This noncompliant code example invokes the wait()
method inside a traditional if
block and fails to check the post-condition after the notification is received. If the notification is accidental or malicious, the thread can wake up prematurely.
...