I read about the issue of thread monitoring restart
http://www.cnblogs.com/ae6623...
The observer mode introduced in this article I think is the key code for restarting the thread Put it in the catch block in the thread body. What should I do if it is an uncaught exception? I don’t know much about the Exception class. Can all exceptions be caught? If so, will there be any missed reasons for thread death? It can’t be monitored
漂亮男人2017-05-27 17:43:04
Exception
是所有异常类的父类, catch(Exception)
Can catch all exceptions
Usually abnormalities are divided into Exception
和RuntimeException
Exception
必须捕获, 发生异常时, 会执行catch
RuntimeException
, 发生异常时, 如果不捕获会中断当前线程, 如果捕获和Exception
same
General conditions for thread exit (death)
Thread business execution completed
Uncaught thread occurredRuntimeException
The essence of restarting the thread in the article you gave is that if the previous thread A
已经结束了(break
), 调用Observable#notifyObservers()
重新启动了一个线程A1
,也就是说如果没有调用Observable#notifyObservers()
is used, the thread will not be restarted.
So, if Observable#notifyObservers()
之前发生了RuntimeException
occurs before calling Observable#notifyObservers()
, and it is not caught, the thread will not be restarted.
PHP中文网2017-05-27 17:43:04
Generally, the location where the observed thread exception occurs can be determined, the exception is caught at the determined location and the thread is restarted. The subject connection method is feasible.