Lesson · Multithreading Fundamentals
Thread Lifecycle: six states and who moves the thread
16 min readThread Lifecycle & States
Thread.State describes what the JVM currently believes about a thread: NEW, RUNNABLE, BLOCKED, WAITING, TIMED_WAITING, TERMINATED. The states are observations, not switches, and reading them correctly is most of what thread dumps are for.
A state is an observation, not a control
The JVM exposes a thread's state through Thread.getState(), and it is a moment in time: the value can change the instant after you read it. There is no setter anywhere in the API, and that is deliberate. States are produced by calls you make and decisions the scheduler takes, never by assigning one.
That also means the class is a description language. It exists so that dumps and diagnostics can tell you where threads are stuck, which is why the wording of a dump matters as much as the enum in this lesson's diagrams.
The six states
Thread.State (Java 5 and later) has exactly six constants, and each one answers a different question: is the thread created, executable, held at a door, parked, parked with a deadline, or finished.
| State | The JVM means | Arrives by |
|---|---|---|
| NEW | created, not started; no thread of execution yet | new Thread(task) |
| RUNNABLE | ready or currently running, plus some native waits | start(), or returning from a wait or a block |
| BLOCKED | at the door of a monitor it cannot enter | reaching synchronized held by another thread |
| WAITING | parked with no deadline | wait(), join(), park() |
| TIMED_WAITING | parked with a deadline | sleep(t), wait(t), join(t), parkNanos |
| TERMINATED | finished: run() returned or threw | the thread ends, once and for all |
You never set a state; you make a call, and the JVM records the consequence. getState() is a photograph of that consequence, taken at one instant.
Who moves a thread
Every transition has an actor: your code calling a method, the scheduler granting a core, or another thread signalling. NEW becomes RUNNABLE when start() is called, and RUNNABLE becomes TERMINATED when run() returns or throws, and those two are the only transitions your code initiates directly.
The three middle states are all about waiting, and they are not the same kind of waiting. BLOCKED is a monitor queue: the thread wants a synchronized block another thread is inside. WAITING and TIMED_WAITING are parks: the thread has stepped aside until a signal, a deadline or an interrupt arrives. Which queue a thread sits in decides whether an interrupt can reach it, so the distinction is practical, not academic.
Thread.State · the whole map
six states, no setterEvery arrow is a call your code makes, a signal another thread sends, or a decision the scheduler takes. Nothing in this picture is set directly.
three ways out, three ways back
enter: synchronized entry while another thread owns the monitor
leave: the monitor is released and entry is granted
interrupt() sets the flag but cannot move this state
enter: wait(), join(), park(): parked with no deadline
leave: notified: back to BLOCKED, then the monitor
leave: target finished, unpark() or interrupt(): RUNNABLE
enter: sleep(t), wait(t), join(t), parkNanos: parked with a deadline
leave: the deadline expires, or interrupt(): RUNNABLE
interrupt() moves WAITING and TIMED_WAITING to RUNNABLE. A BLOCKED thread keeps the flag and stays blocked until it owns the monitor.
RUNNABLE also covers native waits such as socketRead0, so the state alone never proves a thread is burning a core.
RUNNABLE is a bucket, not a promise
The JVM does not distinguish running from ready: both are RUNNABLE, because the scheduler can preempt a running thread at any instruction boundary and the state would be stale as soon as it was written. A RUNNABLE thread may own a core, may be queued behind ten others, or may be sitting in a system call.
That last case is what confuses dump readers. A thread blocked in socketRead0 shows java.lang.Thread.State: RUNNABLE, because a native call the JVM cannot classify leaves the thread runnable from its point of view. It is not burning CPU, it is waiting for a packet.
The JVM's RUNNABLE includes waiting for the CPU, so a dump is a hypothesis, not a verdict. Read the stack frames under the state line before deciding a thread is busy.
BLOCKED, WAITING, TIMED_WAITING
BLOCKED has exactly one cause: monitor entry. If a thread is waiting on ReentrantLock.lock() it reports WAITING, because that lock parks with LockSupport rather than queueing for a monitor. The locks lesson covers why, and the practical consequence here is that a BLOCKED thread in a dump always points at synchronized.
WAITING means no deadline exists: only a notify() or notifyAll(), a join target finishing, an unpark(), or an interrupt ends it. TIMED_WAITING differs only by having a clock attached, so sleep(10), wait(10) and join(10) land there.
| BLOCKED | WAITING | TIMED_WAITING | |
|---|---|---|---|
| Entered by | monitor entry only | wait(), join(), park() | sleep(t), wait(t), join(t), parkNanos |
| Leaves when | the monitor is released and entry is granted | signalled, target finished, unparked, or interrupted | the deadline passes, or interrupted |
| Interrupt | flag set, state unchanged | RUNNABLE, exception thrown | RUNNABLE, exception thrown |
| Dump wording | waiting for monitor entry | in Object.wait(), waiting on condition | TIMED_WAITING (sleeping) |
Interrupt reaches threads that are waiting, not threads blocked on a monitor. A BLOCKED thread keeps the flag and cannot act on it until it owns the monitor.
Interrupt is a request, delivered at a safe point
interrupt() does not stop a thread. It sets the interrupt flag, and if the thread is parked in wait(), join() or sleep(), it wakes it and throws InterruptedException from that call. A running thread just carries the flag until it checks it, which is why cancellation is cooperative.
A BLOCKED thread is the awkward case: the flag is set, the state does not move, and no exception appears, because the thread is not in an interruptible call. It stays at the monitor door, and the exception arrives later, when it gets in and resumes its waiting call. A dump taken while that thread is blocked shows the truth, and it is not the thread you should be aiming at.
Two threads · one monitor
queue · one item in flight
take() waits on empty, put() signals
getState() returns NEW
new Thread(take, "T1")
getState() returns NEW
new Thread(put, "T2")
Two Thread objects and one shared queue. Nothing is running yet: NEW means created, and nothing more.
Reading a dump
A thread dump prints the state twice: in the header line and as a java.lang.Thread.State: line above the stack, with older wording and newer wording saying the same thing. Match the phrases first, then read the frames, then read the lock lines underneath them.
- Find your threads by name.
http-reader-3is readable;Thread-7is not, which is the naming lesson turning into a debugging one. - Read the state line:
BLOCKED (on object monitor)is monitor entry,WAITING (on object monitor)isObject.wait(),WAITING (parking)is a LockSupport park such as ReentrantLock,TIMED_WAITING (sleeping)is a timed sleep. - Read the frames:
- waiting to lock <0x...>names the monitor the BLOCKED thread wants, and- locked <0x...>names the monitor the thread already owns. - Verify before you act: a RUNNABLE thread inside
socketRead0is waiting on the network, not burning a core, whatever the state line says.
Match the phrase, then read the frames. The state tells you which queue a thread is in; the frames and the lock lines tell you who it is waiting for.
What to remember
The lifecycle is small enough to hold in one picture, and the interview angles below only rehearse that picture. These are the sentences worth carrying out of it.
- States are observational: getState() is a snapshot, there is no setter, and the value can change the instant after you read it.
- Two transitions are yours: start() moves NEW to RUNNABLE, and returning from run() moves RUNNABLE to TERMINATED. Everything else needs a caller, a signal or the scheduler.
- BLOCKED is monitor entry only: Lock-based waiting reports WAITING, so a BLOCKED thread in a dump points at synchronized.
- TERMINATED is final: a Thread object runs once, and start() again throws IllegalThreadStateException. Reuse means an executor, not a restart.
notify() does not make a thread runnable
After notifyAll(), the woken thread shows as BLOCKED, not RUNNABLE, and that reads like a bug the first time. It is the protocol: the thread re-queues for the monitor it released when it called wait(), and only becomes RUNNABLE once it owns the monitor again.
Interview angles
Name the six thread states and what moves a thread into each.+
NEW from new Thread(task); RUNNABLE from start(); BLOCKED from entering a synchronized block another thread holds; WAITING from wait(), join() or park(); TIMED_WAITING from their timed forms; TERMINATED when run() returns or throws.
BLOCKED versus WAITING: what is the difference?+
BLOCKED is a monitor queue: the thread cannot enter a synchronized block. WAITING is a park with no deadline, entered by wait(), join() or park(). Both are off the CPU, but interrupt reaches a WAITING thread and bounces off a BLOCKED one.
WAITING, usually shown as WAITING (parking): Lock implementations park with LockSupport instead of queueing for a monitor, so BLOCKED is reserved for synchronized.
Follow-up: So where does a thread waiting on ReentrantLock.lock() appear?
Your dump shows a thread RUNNABLE in socketRead0. Is it consuming CPU?+
Probably not. The JVM maps native calls it cannot classify to RUNNABLE, so a thread waiting for a packet shows RUNNABLE. Read the stack under the state line before drawing a conclusion.
Common misconception: 'RUNNABLE means the thread is using a core.' It means the thread is runnable, may be running, or is inside a native call the JVM does not model. Only the frames tell you which.
Can you interrupt a thread that is blocked on a monitor?+
No. interrupt() sets the flag, the thread stays BLOCKED, and no exception is thrown while it waits at the door. The interrupt is delivered later, when the thread owns the monitor again and resumes an interruptible call.
Why is getState() not a control API?+
It is a snapshot taken while the world moves: the state can change the instant after the read, and there is no setState because states are consequences of calls, not inputs. Code that branches on a state is racing with the scheduler.
With coordination primitives, not polling: join() for thread completion, wait()/notifyAll() or a synchronizer such as CountDownLatch for a condition. Polling getState() in a loop burns a core and still loses races.
Follow-up: How do you wait for a condition then?
What happens if you call start() on a terminated thread?+
IllegalThreadStateException. A Thread object is single use: once run() has returned, that thread is gone for good. Running work again means a new Thread object, or an executor that hands tasks to threads it already has.