skip to content

How does a Java thread move from NEW to TERMINATED, including why it cannot be restarted?

level: juniorimportance: should knowfreq 45%

answer

  1. NEW --start()--> RUNNABLE --run() ends--> TERMINATED
  2. Middle states (BLOCKED/WAITING/TIMED_WAITING) loop back to RUNNABLE
  3. start() spawns a thread; run() does not
  4. Restart throws IllegalThreadStateException
  5. TERMINATED is one-way; create a new Thread to run again

basics

~20 s

A thread starts in NEW after you create it. Calling start() moves it to RUNNABLE. While running it may pass through BLOCKED, WAITING, or TIMED_WAITING. When run() finishes (or throws) it becomes TERMINATED. A terminated thread can't be started again.

solid answer

~50 s

A thread begins life as NEW the moment you construct the Thread object — on HotSpot, no OS thread exists yet. Calling start() (not run()!) on a platform thread creates the underlying OS thread and moves it to RUNNABLE, where the scheduler may run it. During execution it can dip into BLOCKED (waiting for a monitor), WAITING (wait/join/park), or TIMED_WAITING (sleep, timed wait/join), returning to RUNNABLE when unblocked. When the run() method returns normally or propagates an exception, the thread enters TERMINATED — it's dead. You cannot revive it: calling start() on a NEW thread is fine exactly once, but calling start() on a thread that has already started or terminated throws IllegalThreadStateException, because start() accepts only a NEW thread: a thread can be started at most once. Calling run() directly on a platform thread, by contrast, just executes the code on the current thread and never creates a new one.

code

java · 10 lines
java
Thread t = new Thread(() -> System.out.println("working"));
System.out.println(t.getState());  // NEW

t.start();                         // -> RUNNABLE (a real OS thread now runs run())
// t.run();  // WRONG: would run on the current thread, no concurrency

t.join();                          // wait until it finishes
System.out.println(t.getState());  // TERMINATED

t.start();  // throws IllegalThreadStateException — cannot restart

go deeper

for a junior

Can trace NEW → RUNNABLE → TERMINATED and knows start() launches a thread while run() does not.

for a middle

Adds the middle states and their return-to-RUNNABLE transitions, and explains why start() can only be called once.

for a senior

Connects the no-restart rule to thread-pool design (reusable looping workers) and exception propagation out of run().

for a principal

Reasons about lifecycle in terms of resource cost (OS thread creation), pool sizing, and how virtual threads change the create/terminate economics.

## The lifecycle as a journey Think of a thread as having a birth, an active life, and a death — and Java tracks where it is with `Thread.State`. ### 1. Birth: NEW When you write `Thread t = new Thread(runnable);`, you have only a Java object. State = **NEW**. Nothing executes, and on HotSpot no operating-system thread exists yet. You can configure it here (name, daemon flag, priority). ### 2. Launch: start() → RUNNABLE For a platform thread like this one, calling `t.start()` does two things: it asks the OS to create a real thread, and it arranges for that thread to run the `run()` method. The state becomes **RUNNABLE** — meaning eligible to run; the OS scheduler decides when it's actually on a CPU. > **Critical distinction:** `start()` ≠ `run()`. `start()` spawns a new thread that executes `run()`. Calling `run()` *directly* just invokes it like an ordinary method on the **current** thread — no new thread, no concurrency. This is a frequent bug. (That is the platform-thread case; on a virtual thread, the Javadoc says a direct `run()` does nothing.) ### 3. Active life: oscillating through the middle states A RUNNABLE thread doesn't stay running uninterrupted. It can transition to: - **BLOCKED** — trying to enter a `synchronized` region whose monitor is held. - **WAITING** — it called `wait()`, `join()`, or `park()` with no timeout. - **TIMED_WAITING** — it called `sleep(ms)`, a timed `wait(ms)`/`join(ms)`, or `parkNanos`. Each of these returns to **RUNNABLE** once its cause clears (lock acquired, notified, joined-thread done, timeout elapsed, unparked, interrupted), directly or, for a thread woken from `wait()`, by way of BLOCKED while it re-acquires the monitor. A thread may cycle through these many times during its life. ### 4. Death: TERMINATED When `run()` **returns normally** or **throws an exception that propagates out of run()**, the thread finishes and enters **TERMINATED**. In the throwing case the thread's uncaught exception handler is invoked first, and the thread terminates once the handler completes. The OS thread is reclaimed and the call stack is gone. `isAlive()` now returns false. ### 5. Why no restart A `Thread` object can only be `start()`ed **once**. The state machine is one-directional toward TERMINATED; there is no transition back to NEW or RUNNABLE. Calling `start()` on a thread that is not NEW throws **`IllegalThreadStateException`**: `start()` checks the thread's status and refuses anything but NEW, whether the thread is still running or long finished, because the Javadoc says a thread can be started at most once. If you need to 'run it again', create a *new* `Thread` (which is exactly why thread pools reuse worker threads that loop over tasks rather than restarting threads). ## Summary of triggers | Transition | Trigger | |---|---| | NEW → RUNNABLE | `start()` | | RUNNABLE → BLOCKED | contended `synchronized` entry | | RUNNABLE → WAITING | `wait()`/`join()`/`park()` (no timeout) | | RUNNABLE → TIMED_WAITING | `sleep`/`wait(ms)`/`join(ms)`/`parkNanos` | | BLOCKED/WAITING/TIMED_WAITING → RUNNABLE | lock acquired / notified / joined-thread dead / timeout / unpark / interrupt (a thread woken from `wait()` re-acquires the monitor first, via BLOCKED if it is held) | | RUNNABLE → TERMINATED | `run()` returns or throws |

  • What happens if you call start() twice on the same Thread?
    The second call throws IllegalThreadStateException, because the thread is no longer NEW. A Thread can be started exactly once.
  • How do thread pools avoid the 'can't restart' limitation?
    Pool worker threads never terminate per task; they loop, pulling tasks from a queue and executing them, so the same RUNNABLE thread is reused across many tasks.

  • Saying calling run() starts a new thread — it runs on the current thread.
  • Believing a thread can go back to NEW or be restarted after TERMINATED.
  • Thinking start() can be called twice safely.
  • Confusing isAlive() false (terminated) with the ability to restart.

Assumes JDK 27, the same in JDK 25: the run() rule given is the platform-thread one, since a direct run() on a virtual thread, final since JDK 21, does nothing.

context