[ACCEPTED]-Can I start a thread again after it has died?-multithreading

Accepted answer
Score: 12

No, you can't. And the Javadoc for the Thread.start() method 1 tells you that!

Score: 4

From a comment:

Is there anything else I 7 could do to re-start a thread?

You could 6 use ThreadPoolExecutor, which would allow you to pass in tasks 5 and let the service assign a thread to a 4 task. When the task is finished, the thread 3 goes idle until it gets the next task.

So, you 2 don't restart a thread, but you would redo/resume 1 a task.

Score: 0

Nope.

From the Javadoc for java.lang.Thread:

It is never legal to start 1 a thread more than once.

Score: 0

From the javadoc:

It is never legal to start 9 a thread more than once. In particular, a thread 8 may not be restarted once it has completed 7 execution.

See the Thread.start() javadoc for more information.

There 6 are other ways to accomplish what you are 5 trying to do. For example, you could use 4 new Threads that continue the work that 3 was done in the Thread that has finished 2 execution. You may also want to investigate 1 the java.util.concurrent package.

More Related questions