说明
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学习指路:
本教程操作环境:windows7系统、java10版,DELL G3电脑。
Copyright © 2019- how234.cn 版权所有 赣ICP备2023008801号-2
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务