...
This noncompliant code example violates the liveness property. Each thread has a different condition predicate , as because each requires step
to have a different value before proceeding. The Object.notify()
method wakes up only one thread at a time. Unless it happens to wake up the thread that is required to perform the next step, the program will deadlock.
...
Code Block | ||
---|---|---|
| ||
@Override public void run() { try { synchronized (lock) { while (time != step) { lock.wait(); } // Perform operations time++; lock.notifyAll(); // Use notifyAll() instead of notify() } } catch (InterruptedException ie) { Thread.currentThread().interrupt(); // Reset interrupted status } } |
Noncompliant Code Example (Condition
...
Interface)
This noncompliant code example is similar to the noncompliant code example for notify()
but uses the Condition
interface for waiting and notification.
...