Course contentsShow
← Java
Lesson 2592 of 2,87048. Concurrency FundamentalsFree lesson

What Happens During sleep: Thread State Changes

How a sleeping thread moves to TIMED_WAITING state and relinquishes CPU time.

What Happens During sleep: Thread State Changes

What you'll learn: You'll understand exactly how a sleeping thread transitions states and releases CPU resources during Thread.sleep.

The Mechanics of Sleep

When you call Thread.sleep(), something important happens behind the scenes: the thread voluntarily gives up its CPU time and enters the TIMED_WAITING state. This is a crucial cooperative behavior that allows other threads to execute while yours is paused.

Here's the state transition sequence:

  1. Before sleep: Thread is in RUNNABLE state (either actively running or ready to run)
  2. During sleep() call: Thread immediately transitions to TIMED_WAITING state
  3. CPU release: The thread scheduler removes this thread from active consideration—it won't get CPU time until the sleep duration expires
  4. After sleep completes: Thread transitions back to RUNNABLE state (now eligible for CPU time again)

Why TIMED_WAITING?

The TIMED_WAITING state indicates the thread is waiting for a specific, finite duration. Unlike WAITING (indefinite), the JVM knows this thread will automatically wake up after the sleep period expires. The scheduler can completely ignore this thread until then.

The CPU Release

Think of it like voluntarily leaving a busy checkout line and saying, "I'll be back in 5 minutes—serve others until then." The thread doesn't hold onto CPU resources; it's not blocked on a lock, it's not competing for execution time—it's simply dormant.

When the sleep duration expires, the thread doesn't instantly resume execution. It returns to RUNNABLE, meaning it's eligible to run, but must wait its turn with other runnable threads for the scheduler to grant it CPU time.

Key Takeaway: During Thread.sleep(), a thread transitions to TIMED_WAITING, completely relinquishes CPU time, and returns to RUNNABLE when the sleep duration expires—allowing other threads to execute efficiently in the meantime.