1. 当线程处于Blocked状态(sleep,wait,join),线程会退出阻塞状态,并抛出一个InterruptedException.park除外,它有响应但是不会抛出异常 2. 当线程处于Running状态,只是线程的interrupt标记被设置为true,线程本身的运行不会受到任何影响. 上面说得其实还不是特别准确,Java 1.8的Thread.interrupt()方法的注释如下,这个应该是最为权威准确的 Unless the current thread is interrup…
先看三个方法原型: public void interrupt(): public boolean isInterrupted(): public static boolean interrupted(): 一.先说interrupt()方法,看注释 Interrupts this thread. Unless the current thread is interrupting itself, which is always permitted, the checkAccess method…
现有线程对象threadA,调用threadA.interrupt(),则threadA中interrupted状态会被置成false,很多线程中都是通过isInterrupted()方法来检测线程是否中断,但在使用该过程中需要注意,run()方法中是否有其他代码捕获了InterruptedException异常,如果是,则会出现线程无法中断的可能性,主要代码如下: public class DemoTest() { public static void main(String[] args)…
interrupt 下面是interrupt方法的文档的一部分: * <p> If this thread is blocked in an invocation of the {@link * Object#wait() wait()}, {@link Object#wait(long) wait(long)}, or {@link * Object#wait(long, int) wait(long, int)} methods of the {@link Object} * class,…
1 JDK源码跟踪 // java.lang.Thread public void interrupt() { if (this != Thread.currentThread()) checkAccess(); synchronized (blockerLock) { Interruptible b = blocker; if (b != null) { interrupt0(); // Just to set the interrupt flag b.interrupt(this); ret…