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

What Is Starvation?

Understand starvation: when a thread is perpetually denied access to resources despite not being blocked.

What Is Starvation?

You'll learn what thread starvation is and how it differs from deadlock and livelock.

The Core Idea

Starvation occurs when a thread is perpetually denied access to shared resources it needs to make progress, even though it isn't technically blocked or stuck in a loop. The thread is runnable and wants to execute, but the scheduler or other threads keep preventing it from acquiring the resources it needs.

Unlike deadlock (where threads are frozen waiting for each other) or livelock (where threads keep changing state but accomplish nothing), a starving thread is simply being out-competed or unfairly bypassed—sometimes indefinitely.

How Starvation Happens

Starvation typically occurs due to:

  • Unfair lock acquisition: Some threads repeatedly grab a lock before a waiting thread gets its turn
  • Thread priority imbalance: High-priority threads monopolize CPU time (you learned about priority risks in lesson 2631)
  • Long critical sections: If some threads hold locks for extended periods, others may wait forever
  • Resource scheduling: The JVM scheduler or OS may favor certain threads over others

The Hallway Analogy

Imagine a busy hallway where assertive people keep cutting in front of a polite person trying to pass through. The polite person isn't blocked—the path is technically available—but they never get their chance because others keep going first. That's starvation.

Starvation vs Other Issues

  • Deadlock: Threads are mutually blocked, none can proceed
  • Livelock: Threads actively respond but make no progress
  • Starvation: One or more threads could proceed but are continuously denied access

Key Takeaway: Starvation means a thread remains runnable but is perpetually denied the resources it needs, often due to unfair scheduling or aggressive competition from other threads.