how to stop a thread

it seems all stop methods of thread have been deprecated by java. so how to stop a thread then? it is actually simple, just use a boolean variable.

 

public class Test extends Thread{
  
  public boolean running= true;
  
  public void shut(){
    
    running= false;
  }
  
  public void run(){
    
    while(running){
      /*your method goes here*/
    }
    
  }
  
}

 

posted @ 2014-12-06 07:49  zmiao  阅读(151)  评论(0编辑  收藏  举报