商城首页欢迎来到中国正版软件门户

您的位置:首页 >java isInterrupted()怎么判断线程

java isInterrupted()怎么判断线程

  发布于2023-04-26 阅读(0)

扫一扫,手机访问

说明

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是什么

Java是一门面向对象编程语言,可以编写桌面应用程序、Web应用程序、分布式系统和嵌入式系统应用程序。

本文转载于:https://www.yisu.com/zixun/583394.html 如有侵犯,请联系zhengruancom@outlook.com删除。
免责声明:正软商城发布此文仅为传递信息,不代表正软商城认同其观点或证实其描述。

热门关注