JD.LOCK.WAIT
JD.LOCK.WAIT occurs when an Object.wait() method is called while the method is holding two or more locks. This checker checks only local locks.
Vulnerability and risk
Waiting on a monitor while two locks are held may cause deadlock. Performing a wait releases the lock only on the object being waited on, not on any other locks. Not necessarily a problem.
Mitigation and prevention
Preferably, call wait() method without lock held, or with a lock on the same object for which the wait is called.
Example 1
Copy
String name;
synchronized void waitForCondition(Object lock) {
try {
synchronized(lock) {
name = "aa";
lock.wait();
}
} catch (InterruptedException e) {
return;
}
}
JD.LOCK.WAIT is reported for line 14: Calling 'java.lang.Object.wait()' with two or more locks held '[lock, this]' could cause a deadlock.