package com.chenxb.myThread;
class MainState {
public static void main(String[] args) {
Thread thread = new Thread(() ->
{
for (int i = 0; i < 5; i++) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(i);
}
});
Thread.State state = thread.getState();
System.out.println(state);
thread.start();
state = thread.getState();
System.out.println(state);
while (state != Thread.State.TERMINATED) {//线程终止
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
state = thread.getState();
System.out.println(state);
}
//thread.start(); 线程终止后不能再次启动
}
}
Java 线程状态测试
最新推荐文章于 2023-09-14 18:40:51 发布