首页 > 代码库 > how to stop a thread

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*/    }      }  }

 

how to stop a thread