Interrupt线程中断机制

1、Interrupt()

  当该线程处于Runnable状态时,调用Interrupt()设置该线程中断标志

  当线程处于Wait状态时,调用interrupt()该线程抛出异常并清除中断标志

  当线程处于Blocked的状态时,调用interruput(),线程不响应中断,线程会在获得锁后自中断一次

  ReentrantLock锁,在等待队列中的线程处于Wait状态,但是同样不响应中断,获得锁后调用自中断

2、isInterrupted()与interrupted()区别

  前者返回中断标志,后者不但返回中断标志还清除中断标志。

  

猜你喜欢

转载自www.cnblogs.com/mgblogs/p/12104149.html