Java thread monitoring, thread restart, observer mode issues
天蓬老师
天蓬老师 2017-05-27 17:41:04
0
2
588

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

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all (2)
漂亮男人

Exception是所有异常类的父类,catch(Exception)Can catch all exceptions

Usually abnormalities are divided intoExceptionRuntimeException

    Business in
  • Exception必须捕获, 发生异常时, 会执行catch

  • RuntimeException, 发生异常时, 如果不捕获会中断当前线程, 如果捕获和Exceptionsame

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 threadA已经结束了(break), 调用Observable#notifyObservers()重新启动了一个线程A1,也就是说如果没有调用Observable#notifyObservers()is used, the thread will not be restarted.

So, ifObservable#notifyObservers()之前发生了RuntimeExceptionoccurs before callingObservable#notifyObservers(), and it is not caught, the thread will not be restarted.

    Ty80

    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.

      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!