packagecom.seven.threadState;publicclassStateForThread{publicstaticvoidmain(String[] args)throwsException{Thread thread =newThread(()->{for(int i =0; i <10; i++){try{Thread.sleep(1000);}catch(InterruptedException e){
e.printStackTrace();}}System.out.println("------------");});//检测线程的状态Thread.State state = thread.getState();System.out.println(state);
thread.start();while(true){//只要线程没有终止,就可以一直获取状态Thread.sleep(500);
state = thread.getState();System.out.println(state);if(state==Thread.State.TERMINATED)break;}}}