1
JavaIntermediate#concurrency
A deadlock occurs when two or more threads wait on each other's locks indefinitely. Avoid it by acquiring locks in a consistent global order, using timeouts (tryLock), or minimizing nested locking.
// Thread 1: synchronized(lockA) { synchronized(lockB) {...} }
// Thread 2: synchronized(lockB) { synchronized(lockA) {...} }
// Fix: always acquire lockA before lockB in both threads