Is it possible to recover java thread by doing the next?
Thread.setDefaultExceptionHandler(new UncaughtExceptionHandler() {
public void unchaughtException(Thread t, Throwable e) {
t.start();
}
});
Yes it is possible to run a Thread
in a Thread.UncaughtExceptionHandler.uncaughtException
... provided that the Thread
hasn't been started previously.
But it is NOT possible to start the Thread
that was pass as the t
argument. That will (always) be a Thread
that has already been started and has terminated.
You can start a given Thread
at most once. If you try to start one a second time you will get an InvalidStateException
. Always.
No, you cannot run the thread that threw the exception, as shown in your code. It has already run. That's how it threw the exception. A thread cannot be started more than once.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.