Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can a dead thread be restarted? [duplicate]

Tags:

What are all the different possibilities to bring the dead thread back to runnable state.

like image 430
Rakesh KR Avatar asked Aug 14 '13 05:08

Rakesh KR


People also ask

What happens if we start a dead thread?

Once the thread completes its run() method and dead, it cannot be brought back to thread of execution or even to runnable state. Invoking start() method on a dead thread causes runtime exception.

How do I start a dead thread again in Python?

You cannot restart a thread. When a thread finished, its stack is dead; its parent is flagged or signaled; once it's joined, its resources are destroyed (including kernel-level resources like its process table entry). The only way to restart it would be to create a whole new set of everything.

Can we started thread twice?

No. After starting a thread, it can never be started again. If you does so, an IllegalThreadStateException is thrown. In such case, thread will run once but for second time, it will throw exception.

Which method is used to dead the thread?

A thread dies naturally when its run() method exits normally. For example, the while loop in this method is a finite loop--it will iterate 100 times and then exit. A thread with this run() method will die naturally after the loop and the run() method completes.


Video Answer


1 Answers

Thread lifecycle image

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.

like image 72
Nargis Avatar answered Oct 01 '22 16:10

Nargis