Java › Concurrency & Threads

How would you diagnose a suspected thread deadlock in a running production JVM using a thread dump, and what specific information in the dump reveals the deadlock?

Advanced

Answer

A thread dump (obtainable via jstack <pid>, or a JMX-based tool, or sending SIGQUIT to the JVM process on Unix) captures the current state and stack trace of every live thread at that moment -- the JVM's built-in deadlock detection (included automatically in a thread dump when applicable) explicitly identifies and reports any detected deadlock cycle, listing each involved thread, the lock it currently holds, and the lock it's waiting to acquire, letting you directly trace the circular dependency; threads stuck in a deadlock typically show a BLOCKED state along with a stack trace pointing at the exact synchronized block or lock.lock() call where they're stuck.
# Generate a thread dump for a running Java process
jstack <pid> > threaddump.txt

# The output includes an explicit section like:
# "Found one Java-level deadlock:"
# "Thread-0" waiting to lock monitor 0x... (object lockB), which is held by "Thread-1"
# "Thread-1" waiting to lock monitor 0x... (object lockA), which is held by "Thread-0"
Real-world example An on-call engineer investigating a production service that suddenly stopped responding to any requests captures a thread dump via jstack, immediately spotting the JVM's own explicit "Found one Java-level deadlock" report identifying the exact two threads and locks involved, dramatically speeding up root-cause diagnosis compared to guessing from application logs alone.

Common follow-ups: What's the difference between a thread in BLOCKED state versus WAITING versus TIMED_WAITING in a thread dump?;How would you capture a thread dump automatically as part of an incident response runbook without manual intervention?