如何停止在没有任何使用的情况下永久运行的线程
2022-09-01 20:00:28
在下面的代码中,我有一个 while(true) 循环。考虑到在try块中有一些代码的情况,其中线程应该执行一些任务,大约需要一分钟,但由于一些预期的问题,它永远在运行。我们可以停止那个线程吗?
public class thread1 implements Runnable {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
thread1 t1 = new thread1();
t1.run();
}
@Override
public void run() {
// TODO Auto-generated method stub
while(true){
try{
Thread.sleep(10);
}
catch(Exception e){
e.printStackTrace();
}
}
}
}