java的中断线程interrupt()方法,为什么还要把run()方法走完呢?那中断线程不就没有意义了吗?
高洛峰
高洛峰 2017-04-18 09:33:34
0
2
720

当线程调用interrupt方法后,为什么还要运行完run方法呢?那中断线程还有什么意义?

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(2)
刘奇

Java interrupt mechanism is a cooperative mechanism, which means that another thread cannot be directly terminated through interruption, and the interrupted thread needs to handle the interruption by itself. This is like parents at home telling their children to take care of their health, but whether and how their children take care of their health is entirely up to them.

Detailed analysis of Java interrupt mechanism

黄舟

Java threads also have a way to prevent the run method from completing, and that is the stop method. However, this method has been deprecated by jdk. Why? If your thread is modifying data somewhere, be it a database or writing a file, and the stop method kills the thread without any explanation, will the data be chaotic or inconsistent? Therefore, Java threads use an interrupt mechanism, and you can capture this interrupt and perform the operations required after the interruption.

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!