Return停止线程: 使用interrupt()和return结合也可以实现停止线程的效果.不过还是建议使用“抛异常“的方法,因为在catch块中可以将异常向上抛,使线程停止的事件得以传播. public class ReturnInterruptThread extends Thread{ @Override public void run() { while (true){ if (this.isInterrupted()){ System.out.println("Stop thread…
调用interrupt方法仅仅是在当前线程中打了一个停止的标记,并不是真正停止线程. this.interrupted() :测试当前线程是否已经中断,执行后具有将状态标志清除为false的功能 isInterrupted() : 测试线程Thread对象是否已经是中断状态,但不清除状态标志. public class InterruptDemo extends Thread{ public void run(){ super.run(); try{ for(int i =0;i< 5000…