Files
openide/java/java-impl/resources/inspectionDescriptions/WaitWhileHoldingTwoLocks.html
2025-02-05 04:43:28 +00:00

23 lines
591 B
HTML

<html>
<body>
Reports calls to <code>wait()</code> methods that may occur while the current thread is holding two locks.
<p>
Since calling <code>wait()</code> only releases one lock on its target,
waiting with two locks held can easily lead to a deadlock.
</p>
<p><b>Example:</b></p>
<pre><code>
synchronized (lockA) {
synchronized (lockB) {
lockB.wait(); //warning
//thread A is stuck here holding lockA
}
}
synchronized (lockA) { //thread B can't enter the block and release thread A
lockB.notify();
}
</code></pre>
<!-- tooltip end -->
</body>
</html>