在java中杀死正在运行的线程? [英] killing a running thread in java?

查看:1434
本文介绍了在java中杀死正在运行的线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在java中终止正在运行的线程

How to kill a running thread in java

推荐答案

您可以通过调用 Thread.interrupt ()

You can ask the thread to interrupt, by calling Thread.interrupt()

请注意,存在一些具有类似语义的其他方法 - stop() destroy() - 但它们已弃用,因为它们是不安全。不要试图使用它们。

Note that a few other methods with similar semantics exist - stop() and destroy() - but they are deprecated, because they are unsafe. Don't be tempted to use them.

这篇关于在java中杀死正在运行的线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆