对于线程中断,需要注意的几点:
interrupt() 让阻塞的线程中断处理
try{
Thread.sleep(3000L);
}catch(InterruptedException e){
/*************************
运行interrupt()后会抛出InterruptedException 异常
如果希望中断处理的话,需要做如下操作:
1. 抛出异常
2. 在异常代码中执行 Thread.currentThread().interrupt();
3. 或在异常代码中执行 interrupt();
****************************/
}
interrupt() 让当前线程中断处理 interrupted() 检查当前线程是否中断, 并清除中断 isInterrupted() 查看当前线程的中断状态,true-中断; false-未中断