说明
1、isInterrupted()可以判断当前线程是否被中断,仅仅是对interrupt()标识的一个判断,并不会影响标识发生任何改变2、调用interrupt()的时候会设置内部的一个叫interrupt flag的标识)。
实例
public static void main(String[] args) throws InterruptedException{ Thread thread = new Thread(()->{ while (true){} }); thread.start(); TimeUnit.SECONDS.sleep(1); System.out.println("Thread is interrupted :"+thread.isInterrupted()); thread.interrupt(); System.out.println("Thread is interrupted :"+thread.isInterrupted()); }
以上就是java isInterrupted()判断线程的方法,希望对大家有所帮助。 更多Java学习指路: Java基础
本教程操作环境:windows7系统、java10版,DELL G3电脑。
查看更多关于java isInterrupted()如何判断线程的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did248801