Course contentsShow
← Java
Lesson 2578 of 2,87048. Concurrency FundamentalsFree lesson

The IllegalThreadStateException

Attempting to start the same Thread instance twice throws an exception.

The IllegalThreadStateException

What you'll learn: You'll discover what happens when you try to start the same Thread instance more than once and why Java prevents this with an exception.


Why You Can't Restart a Thread

Once you call start() on a Thread instance, that thread begins executing its run() method. After start() has been invoked, Java considers that thread "started"—and you cannot start it again.

If you attempt to call start() on the same thread object a second time, Java throws an IllegalThreadStateException. This happens even if the thread has already finished executing its task.

Think of it like launching a rocket: once the rocket has launched, you can't press the launch button again on the same rocket. You'd need to build a new rocket (create a new Thread instance).


When This Exception Occurs

Thread t = new Thread(() -> System.out.println("Running..."));
t.start(); // First start — OK

// Later in your code:
t.start(); // IllegalThreadStateException thrown here!

The second start() call is illegal because the thread's internal state has already transitioned from "new" to "started." Java enforces this rule strictly to prevent undefined behavior in the threading system.


The Solution

If you need to execute the same task multiple times, create a new Thread instance each time:

Runnable task = () -> System.out.println("Running...");

Thread t1 = new Thread(task);
t1.start(); // First execution

Thread t2 = new Thread(task);
t2.start(); // Second execution with a new thread

Notice we reuse the Runnable, but each call to start() uses a fresh Thread object.


Key Takeaway: A Thread instance can only be started once; attempting to call start() a second time throws an IllegalThreadStateException. Always create a new Thread object if you need to run the same task again.