Course contentsShow
← Java
Lesson 2703 of 2,87049. Synchronization and LockingFree lesson

Detecting Livelock vs Deadlock

Learn how to distinguish livelock (high CPU, active threads) from deadlock (no CPU activity, blocked threads).

Detecting Livelock vs Deadlock

What you'll learn: How to distinguish between livelock (where threads are active but making no progress) and deadlock (where threads are completely blocked).

The Core Difference

While both livelock and deadlock prevent your program from making progress, they exhibit completely different symptoms that allow you to diagnose which problem you're facing.

Deadlock occurs when threads are waiting for each other to release locks, forming a circular dependency. The threads are blocked and doing absolutely nothing—they're stuck in a waiting state.

Livelock occurs when threads are actively responding to each other's actions but keep changing state in a way that prevents progress. The threads are running and consuming CPU cycles, but they're stuck in a repetitive pattern of activity.

Observable Symptoms

When diagnosing deadlock:

  • CPU usage: Near zero for the affected threads
  • Thread state: BLOCKED or WAITING
  • Thread dumps: Show circular lock dependencies
  • Activity: Threads appear frozen, making no progress

When diagnosing livelock:

  • CPU usage: High—threads are actively executing
  • Thread state: RUNNABLE
  • Thread dumps: Threads show active execution, not blocked
  • Activity: Threads are busy but accomplishing nothing (like our polite workers continuously yielding to each other)

How to Detect

Use monitoring tools like jstack or thread dumps. In deadlock, you'll see threads waiting on locks held by other threads. In livelock, threads will be in runnable states, possibly with repeated patterns in stack traces showing the same methods being called over and over.

Check CPU usage: sustained high CPU with no progress suggests livelock; low CPU with no progress suggests deadlock.

Key Takeaway: Deadlock shows blocked threads with no CPU activity; livelock shows runnable threads burning CPU cycles but making no progress—understanding these signatures helps you quickly identify which concurrency problem you're facing.