线程转态转换图

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/615a5c57-1ad1-4450-af8b-cec5cd34f2c7/IMG_0261.jpg

代码演示

public class ThreadState_ {
    public static void main(String[] args) throws InterruptedException {
        T t = new T();
        t.setName("线程1");
        System.out.println(t.getName()+" 状态 "+t.getState());
        t.start();

        while (Thread.State.TERMINATED !=t.getState()){
            System.out.println(t.getName()+" 状态 "+t.getState());
            Thread.sleep(500);
        }

        System.out.println(t.getName()+" 状态 "+t.getState());
    }
}

class T extends Thread{
    @Override
    public void run() {
        while (true){
            for (int i = 0; i <10 ; i++) {
                System.out.println("hi "+ i);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            break;
        }
    }
}