isAlive
活动状态:线程处于正在运行或准备开始运行的状态

public class ISLiveDemo extends Thread {

    public void run() {
        System.out.println("run:" + isAlive());
    }

    public static void main(String[] args) throws InterruptedException {
        ISLiveDemo live = new ISLiveDemo();
        System.out.println("begin:" + live.isAlive());
        live.start();
        Thread.sleep(1000);

        System.out.println("end:" + live.isAlive());
    }
}
System.out.println("end:" + live.isAlive());
输出结果是不确定。
 上面的输出结果为false,因为live对象已经在1秒内执行完毕。

相关文章:

  • 2021-04-07
  • 2021-09-13
  • 2021-11-20
  • 2021-06-06
  • 2021-07-11
  • 2021-05-23
  • 2021-05-12
  • 2022-12-23
猜你喜欢
  • 2021-06-23
  • 2021-12-22
  • 2021-09-13
  • 2021-07-28
  • 2021-07-07
  • 2021-12-19
相关资源
相似解决方案