多线程
作者:互联网
线程状态
-
运行状态:
- 新生 NEW
- 就绪
- 运行 RUNNABLE
- 死亡 阻塞
- TERMINATED 终止 == 死亡
package com.company.demo.test;
public class Demo10_state {
public static void main(String[] args) {
// 里面写的是run方法,使得线程能维持一段时间
Thread thread = new Thread(() -> {
try {
Thread.sleep(100);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("**************");
});
System.out.println(thread.getState());//NEW
thread.start();
System.out.println(thread.getState()); //RUNNABLE
while (thread.getState() != Thread.State.TERMINATED) {
try {
thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("线程状态:"+thread.getState());
}
System.out.println("**************");
System.out.println(thread.getState());
}
}
标签:getState,Thread,thread,System,println,多线程,out 来源: https://blog.51cto.com/u_15202146/2777534