ABSTRACT

It is ambiguous which thread will wake up when notify() is called.

EXPLANATION

There is no way to specify which thread will be awakened by calls to notify().

Example 1: In the following code, notifyJob() calls notify().


public synchronized notifyJob() {
flag = true;
notify();
}
...
public synchronized waitForSomething() {
while(!flag) {
try {
wait();
}
catch (InterruptedException e)
{
...
}
}
...
}

In this case, the developer intends to wake up the thread that calls wait(), but it is possible that notify() will notify a different thread than the intended one.

REFERENCES

[1] Standards Mapping - Common Weakness Enumeration - (CWE) CWE ID 373

[2] Sun Microsystems, Inc. Java Sun Tutorial - Concurrency

[3] Sun Microsystems, Inc. Java Sun Tutorial - Concurrency