不用担心,文档
interrupt指出:
如果在调用Object类的wait(),wait(long)或wait(long,int)方法或join(),join(long),join(long,int)方法时阻塞了此线程,此类的sleep(long)或sleep(long,int)方法,则其中断状态将被清除,并将收到InterruptedException。
因此,只有
InterruptedException在处于某种阻塞/睡眠/等待状态时,线程才会获取。如果您正在运行,则线程在进入这些状态之一之前不会获得异常。
您的循环应为:
while(!Thread.currentThread().isInterrupted()) // <- something of the sort here{ try{ // do work } catch (InterruptedException e){ // clean up }}更新:
此外,文档指出:
如果上述条件均不成立,则将设置该线程的中断状态。



