Using UncaughtExceptionHandler effectively

后端 未结 2 831
Happy的楠姐
Happy的楠姐 2020-12-30 18:21

I got to know about this Java 1.5 capability recently and I developed a sample code to use this. My objective is to restart the thread when it gets dead due to an uncaught e

2条回答
  •  感动是毒
    2020-12-30 18:51

    You should not restart the thread that is about to exit. The method is invoked when the given thread terminates. So you can only create and start a new thread. If you know about the threads class (by instanceof...) you can obtain the runnable from it and create a new thread in the terminating threads group and start it from the UncaughtExceptionHandler.

    But aware: I would check for specific exceptions. A minimum can be: restart only if the throwable is a runtime exception, not an error!

提交回复
热议问题