博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【Thread】java类Thread中提供了检测线程是否中断的方法,说一说你的了解?
阅读量:6590 次
发布时间:2019-06-24

本文共 1727 字,大约阅读时间需要 5 分钟。

  hot3.png

     Thread类中提供了两个检测线程是否中断的方法,一个是静态方法调用,一个是成员方法调用。并且静态方法调用会清除当前线程的是否中断的状态。

 

参考资料:

jdk源码

/**     * Tests whether the current thread has been interrupted.  The     * interrupted status of the thread is cleared by this method.  In     * other words, if this method were to be called twice in succession, the     * second call would return false (unless the current thread were     * interrupted again, after the first call had cleared its interrupted     * status and before the second call had examined it).     *     * 

A thread interruption ignored because a thread was not alive * at the time of the interrupt will be reflected by this method * returning false. * * @return true if the current thread has been interrupted; * false otherwise. * @see #isInterrupted() * @revised 6.0 */ public static boolean interrupted() { return currentThread().isInterrupted(true); } /** * Tests whether this thread has been interrupted. The interrupted * status of the thread is unaffected by this method. * *

A thread interruption ignored because a thread was not alive * at the time of the interrupt will be reflected by this method * returning false. * * @return true if this thread has been interrupted; * false otherwise. * @see #interrupted() * @revised 6.0 */ public boolean isInterrupted() { return isInterrupted(false); } /** * Tests if some Thread has been interrupted. The interrupted state * is reset or not based on the value of ClearInterrupted that is * passed. */ private native boolean isInterrupted(boolean ClearInterrupted);

 

转载于:https://my.oschina.net/u/914290/blog/802186

你可能感兴趣的文章
React组件: 提取图片颜色
查看>>
3D应用开发中的欧拉角和旋转矩阵
查看>>
爬虫必备技能xpath的用法和实战
查看>>
MacOS下安装Grafana、InfluxData、telegraf
查看>>
RxJava2.0的初学者必备教程(九)
查看>>
记一次omi的项目之旅
查看>>
Android API级别、代号、发布时间及平台亮点整理
查看>>
安装配置nagios
查看>>
QQ第三方授权登录(带详细源码)
查看>>
LLDP(链路层发现协议)
查看>>
Ubuntu14 添加程序启动
查看>>
我的友情链接
查看>>
windows网络安全以及常见网络***方式
查看>>
警告 初始化默认驱动器时出错“找不到运行 Active Directory Web 服务的默认服务器。”...
查看>>
JS字符串转换数字
查看>>
centos7-修改主机名
查看>>
面试宝典系列-mysql面试基础题
查看>>
微信硬件平台对接--蓝牙
查看>>
spring data for mongo
查看>>
开启 URL 重写
查看>>