What are all the different possibilities to bring the dead thread back to runnable state.
-
1None! You are much better off wrapping the state of your thread in an object (perhaps a `Runnable`), and merely passing this object to a new thread. – phs Aug 14 '13 at 05:38
-
You can't restart a thread! – Rubens Mariuzzo Aug 14 '13 at 05:38
-
6You need to use advanced time travel techniques. And you have to avoid creating paradoxes ... like when a thread does back in time and kills its parent thread before it is created. – Stephen C Aug 14 '13 at 05:41
-
@StephenC I guess ATTT is included in Java 8, isn't it? :-) – Uooo Aug 14 '13 at 05:43
-
There is an attt8.jar – Rubens Mariuzzo Aug 14 '13 at 05:52
-
@Uooo - Yes, but there are export restrictions, especially if you come from Skaro. – Stephen C Aug 14 '13 at 06:15
-
No you can't. Once the thread is dead it won't starts again. To start the thread again you need to suspend the thread so it can be resumed. – Vighanesh Gursale Aug 15 '13 at 07:01
7 Answers
If you look at the Thread Life Cycle Image, there is no way you can go back to new position once your thread has terminated.
So there is no way to bring back the dead thread to runnable state,instead you should create a new Thread instance.
-
7
-
3+1 nice post. @Uooo Open this [link](http://faculty.inverhills.mnscu.edu/speng/cs1127/Notes/Ch23/LifeCycle.htm) and click on UML diagram – Suresh Atta Aug 14 '13 at 05:46
From the JavaDocs...
It is never legal to start a thread more than once. In particular, a thread may not be restarted once it has completed execution.
You'll have to start a brand new instance.
Preferably, the actions you want to execute should be wrapped up in a Runnable
interface, that way you can simply pass the Runnable
to a new instance of Thread

- 343,457
- 22
- 230
- 366
I guess you extended the Thread
class and you have overridden the run
method. If you do this you are tying the runnable code to the Thread
's lifecycle. Since a Thread
can not be restarted you have to create a new Thread
everytime. A better practice is to separate the code to run in a thread from a Thread
's lifecycle by using the Runnable
interface.
Just extract the run
method in a class that implements Runnable
. Then you can easily restart it.
For example:
public class SomeRunnable implements Runnable {
public void run(){
... your code here
}
}
SomeRunnable someRunnable = new SomeRunnable();
Thread thread = new Thread(someRunnable);
thread.start();
thread.join(); // wait for run to end
// restart the runnable
thread = new Thread(someRunnable);
thread.start();
This practice makes it also easy if you need to remember the previous run state.
public class SomeRunnable implements Runnable {
private int runs = 0;
public void run(){
runs++;
System.out.println("Run " + runs + " started");
}
}
PS: Use a java.util.concurrent.Executor
to execute Runnable
s. This will decouple thread management from execution.
Executor executor = Executors.newSingleThreadExecutor();
...
SomeRunnable someRunnable = new SomeRunnable();
executor.execute(someRunnable);
Take a look at Executor Interfaces

- 48,224
- 13
- 108
- 140
The thread is a separate light weight process which executes independently irrespective of other threads. Once its execution is complete, there exists no means to restart it.

- 1,167
- 9
- 20
The other obvious solution is: if you need the thread functionality many times, don't let the thread die. Instead of letting it exit, and so terminate itself, shove in a while(true) loop with a suitable wait at the top. You can then make it 'restart' its work by signaling it.
This is much quicker, safer and more efficient than continually creating/terminating/destroying threads.

- 34,448
- 50
- 182
- 322

- 24,453
- 3
- 36
- 60
When the execution of run() method is over, as the job it is meant is done, it is brought to dead state. It is done implicitly by JVM. In dead state, the thread object is garbage collected. It is the end of the life cycle of thread. Once a thread is removed, it cannot be restarted again (as the thread object does not exist).
Read more From Here about life cycle of Threads.

- 7,636
- 5
- 37
- 49
Thread has many different state through out its life.
1 Newborn State
2 Runnable State
3 Running State
4 Blocked State
5 Dead State
Thread should be in any one state of above and it can be move from one state to another by different methods and ways.
When a thread is completed executing its run() method the life cycle of that particular thread is end.
We can kill thread by invoking stop() method for that particular thread and send it to be in Dead State.

- 736
- 6
- 15