停止线程
-
Java中如何停止线程 详解安全终止线程的正确方法
避免thread.stop()带来的问题需采用协作式中断机制。1. 不直接调用thread.stop(),而是通过interrupt()方法设置中断状态并由线程自身检查isinterrupted()或捕获interruptedexception来决定何时退出;2. 使用volatile变量确保多线程…
*本站广告为第三方投放,如发生纠纷,请向本站索取第三方联系方式沟通
避免thread.stop()带来的问题需采用协作式中断机制。1. 不直接调用thread.stop(),而是通过interrupt()方法设置中断状态并由线程自身检查isinterrupted()或捕获interruptedexception来决定何时退出;2. 使用volatile变量确保多线程…