Java多线程(四)isAlive

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秒内执行完毕。

转载于:https://www.cnblogs.com/newlangwen/p/7592848.html

你可能感兴趣的:(Java多线程(四)isAlive)