线程 的状态

1,刚new出来,新生状态

2,start()后为就绪状态,等着cpu的调度,调度后,运行状态

3,跑完或者stop为死亡状态

4,阻塞,有join,yied,sleep,I/o资源,比如readLine,

而当阻塞消除时,又为就绪状态

public class StopDemo1 {

    public static void main(String[] args) {
        Cat c=new Cat();
        Thread t=new Thread(c);
        t.start();
        
        for(int i=0;i<1000;i++){
            if(i==400){
                c.stop();
            }
        }
    }
    
}

class Cat implements Runnable{
    
    private  boolean flag=true;
    
    @Override
    public void run() {
        while(flag){
            System.out.println("cat========");
        }
        
    }
     
    public void stop(){
        this.flag=false;
    }

}
原文地址:https://www.cnblogs.com/bashala/p/3615385.html