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
Exception
是所有异常类的父类,catch(Exception)
Can catch all exceptionsUsually abnormalities are divided into
Exception
和RuntimeException
Business in
Exception
必须捕获, 发生异常时, 会执行catch
RuntimeException
, 发生异常时, 如果不捕获会中断当前线程, 如果捕获和Exception
sameGeneral conditions for thread exit (death)
Thread business execution completed
Uncaught thread occurred
RuntimeException
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 callingObservable#notifyObservers()
, and it is not caught, the thread will not be restarted.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.