你如何杀死Java中的线程? [英] How do you kill a Thread in Java?
本文介绍了你如何杀死Java中的线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Java中杀死 java.lang.Thread
?
How do you kill a java.lang.Thread
in Java?
推荐答案
请参阅此 Sun关于他们弃用的原因的帖子使用Thread.stop()
。它详细介绍了为什么这是一个糟糕的方法,以及应该采取什么措施来安全地停止线程。
See this thread by Sun on why they deprecated Thread.stop()
. It goes into detail about why this was a bad method and what should be done to safely stop threads in general.
他们推荐的方法是使用共享变量作为标志,要求后台线程停止。然后,该变量可以由请求线程终止的不同对象设置。
The way they recommend is to use a shared variable as a flag which asks the background thread to stop. This variable can then be set by a different object requesting the thread terminate.
这篇关于你如何杀死Java中的线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文