A deadlock is a permanent standstill: two or more threads each hold a lock the other needs, so none can ever proceed. It is the classic failure mode of lock-based concurrency, and the moment you take more than one lock you have to reason about the order in which threads acquire them. Livelock and starvation are its quieter cousins — the threads are not blocked, yet useful work still never gets done.
The four Coffman conditions
A deadlock can only happen when all four conditions hold simultaneously. Break any one and deadlock becomes impossible:
- Mutual exclusion — a resource (lock) is held by at most one thread at a time.
- Hold and wait — a thread holds one lock while waiting to acquire another.
- No preemption — a lock cannot be forcibly taken away; the holder must release it voluntarily.
- Circular wait — there is a cycle of threads, each waiting on a lock held by the next.
The cycle is the part you can actually see in a thread dump, and the one prevention strategies target most directly — impose a global lock-ordering and a cycle becomes impossible.
Thread-1 holds A ---- wants ----> Lock B ^ | | v Lock A <---- wants ---- Thread-2 holds B
Liveness failures beyond deadlock
Deadlock is one of three liveness problems. Livelock: threads are actively running and responding to each other, but their states keep changing in a way that prevents progress — like two people stepping aside in the same direction in a hallway, forever. A common cause is a retry-on-conflict loop where every thread backs off in lockstep. Starvation: a thread is perpetually denied a resource it needs — typically because a greedy or higher-priority thread (or an unfair lock) keeps winning the race. The thread could run, but never gets scheduled the resource.
Detection vs prevention
The JVM does not prevent deadlock for you — synchronized and ReentrantLock will happily form a cycle. Your tools are prevention (consistent lock ordering, tryLock with timeout, shrinking critical sections, open calls) and detection (thread dumps and ThreadMXBean). The questions in this topic walk through reproducing a deadlock, reading it in a dump, and designing it away.