package com.study.concurrent.thread.state;
import static java.lang.Thread.*;
public class ThreadStateDemo1_Sleep {
static volatile boolean running = true;
public static void main(String[] args) throws Throwable {
Thread t1 = new Thread(() -> {
try {
while (running) {
System.out.println("------");
}
System.out.println(" t1 running is false . t1 将 sleep 了 ");
Thread.sleep(10000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
});
System.out.println("new t1 t1的状态: " + t1.getState());
t1.start();
Thread.sleep(2000L);
System.out.println("t1.start()后的状态: " + t1.getState());
running = false;
System.out.println("t1.sleep() 的状态: " + t1.getState());
}
}
标签:状态,Thread,查看,System,t1,running,线程,println,out From: https://blog.51cto.com/u_11343833/6091639