子线程interrupted,在catchException之后,重新设置了此线程为已中断的状态,为什么在代码的最后一行获取的状态仍然是false?
public class TheadStatusTest {
public static void main(String[] args) throws InterruptedException {
Thread s = new Thread(()->{
try {
System.out.println(Thread.currentThread().getName());
Thread.sleep(Integer.MAX_VALUE);
} catch (InterruptedException e) {
//抛出异常后,线程的标示位已经clear成false了
// 这里返回false
System.out.println("INTERRUPTED ..." + Thread.currentThread().isInterrupted());
// System.out.println("INTERRUPTED ..." + Thread.interrupted()); //
e.printStackTrace();
//重新设置标示位
Thread.currentThread().interrupt();
// 这里返回ture
System.out.println("INTERRUPTED 2 ..." + Thread.currentThread().isInterrupted());
}
}, "Abc-thread-");
s.start();
//设置线程标示位为true //
s.interrupt();
Thread.sleep(1000);
System.out.println("===>"+ s.isInterrupted()); //这个状态是在main.sleep之后获取的,为什么是false?
}
}