TERMINATED State: Thread Completion
What you'll learn: How and when a thread enters the TERMINATED state, marking the end of its lifecycle.
The Final State
The TERMINATED state is the final destination for every thread. Once a thread reaches this state, it cannot be restarted or reused—its lifecycle is permanently over. A thread enters TERMINATED when its run() method completes normally or when an uncaught exception causes it to terminate abruptly.
Think of a thread like a one-way train journey: once the train reaches its final station (TERMINATED), that particular train can never make another trip. You'd need to create a new train (thread) for a new journey.
How Threads Become TERMINATED
There are two primary paths to TERMINATED:
Normal Completion
When the run() method finishes executing all its statements and returns, the thread gracefully transitions to TERMINATED. The thread has completed its work as designed.
Uncaught Exception
If an exception is thrown inside run() and not caught anywhere in the thread's execution stack, the thread terminates abnormally. The uncaught exception kills the thread immediately.
Why This Matters
Once TERMINATED, calling start() on that thread object again throws an IllegalThreadStateException. The thread object still exists as a Java object, but its execution capability is gone forever. This is why you must create a new thread if you need to repeat the same task.
You can check if a thread has terminated using thread.getState() == Thread.State.TERMINATED or !thread.isAlive().
Key Takeaway: TERMINATED is the permanent end state of a thread's lifecycle, reached when run() completes normally or an uncaught exception occurs; a terminated thread cannot be restarted.