What are the states in a thread's lifecycle?

7 minintermediatethread-lifecyclethread-states

Quick Answer

A Java thread moves through NEW (created, not started), RUNNABLE (executing or eligible to run, includes what the OS might call 'ready' or 'running'), BLOCKED (waiting to acquire a monitor lock), WAITING (waiting indefinitely for another thread's signal), TIMED_WAITING (waiting for a bounded time), and TERMINATED (finished execution).

Detailed Answer

Thread.State (queryable via thread.getState()) defines six states:

  1. NEW: the Thread object has been created but start() hasn't been called yet.
  2. RUNNABLE: the thread is executing, or is eligible to execute and waiting for CPU time from the OS scheduler — Java doesn't distinguish "actually running" from "ready to run" at the language level; both map to RUNNABLE.
  3. BLOCKED: the thread is waiting to acquire a monitor lock to enter a synchronized block/method that another thread currently holds.
  4. WAITING: the thread is waiting indefinitely for another thread to perform a specific action — e.g., it called Object.wait() (no timeout), Thread.join() (no timeout), or LockSupport.park().
  5. TIMED_WAITING: like WAITING, but bounded by a timeout — e.g., Thread.sleep(ms), Object.wait(timeout), Thread.join(timeout).
  6. TERMINATED: the thread's run() method has completed (normally or via an uncaught exception); it cannot be restarted.
Thread t = new Thread(() -> { try { Thread.sleep(1000); } catch (InterruptedException e) {} });
t.getState(); // NEW
t.start();
t.getState(); // RUNNABLE (or briefly TIMED_WAITING once sleep() kicks in)
t.join();
t.getState(); // TERMINATED

A common interview follow-up: BLOCKED vs WAITINGBLOCKED specifically means contending for a lock to enter a synchronized region; WAITING means the thread voluntarily gave up execution and is waiting for a signal (notify()/notifyAll()) or another thread to finish, having already been inside (or without needing) a lock.

Related Resources