State Transitions: Valid Paths Between States
You'll learn: How threads legally move between the five lifecycle states and which transitions are impossible.
Understanding the Valid Transition Map
Not every state can directly transition to every other state. A thread follows strict rules when moving through its lifecycle, and understanding these paths helps you reason about concurrent behavior and diagnose threading issues.
The Valid Transitions
Here's what's allowed:
From NEW:
- NEW → RUNNABLE (only via
start())
From RUNNABLE:
- RUNNABLE → BLOCKED (when attempting to acquire a monitor lock held by another thread)
- RUNNABLE → WAITING (via
wait(),join(), orpark()without timeout) - RUNNABLE → TIMED_WAITING (via
sleep(), timedwait(), timedjoin()) - RUNNABLE → TERMINATED (when
run()completes or throws an exception)
From BLOCKED:
- BLOCKED → RUNNABLE (only when the monitor lock becomes available)
From WAITING:
- WAITING → RUNNABLE (when notified or joined thread completes)
From TIMED_WAITING:
- TIMED_WAITING → RUNNABLE (when timeout expires or condition is met)
From TERMINATED:
- No transitions possible (terminal state)
Impossible Transitions
You cannot:
- Go from NEW directly to BLOCKED, WAITING, or TIMED_WAITING
- Go from BLOCKED directly to WAITING or TIMED_WAITING
- Return from TERMINATED to any state
- Skip RUNNABLE when moving between waiting states
Think of it like a subway map: certain stations (states) only connect directly to specific others. You can't teleport arbitrarily between them.
Key Takeaway: Thread state transitions follow strict rules—threads always pass through RUNNABLE when moving between active states, NEW threads can only transition via start(), and TERMINATED is a one-way destination with no exit.