关于while (!Thread.currentThread().isInterrupted()){}的意思

来源:互联网 发布:百战天下坐骑进阶数据 编辑:程序博客网 时间:2024/05/22 11:43

在Java代码中常常看到这个代码:

 

while (!Thread.currentThread().isInterrupted()){     ... ...}

 

这是什么意思呢?


Thread.currentThread()返回当前线程对象引用

.isInterrupted()测试是否当前线程已被中断 中断返回true,否则返回false

总的说,这句就是无限判断当前线程状态,如果没有中断,就一直执行while内容。


 

0 0
原创粉丝点击