/** @return <code>true</code> if this thread has been interrupted; * <code>false</code> otherwise. * 默认返回false, 处于未中断状态;如果被中断返回false */ public boolean isInterrupted() { return isInterrupted(false); }
// 设置中断状态,再次调用isInterrupted()会返回true 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); return; } } interrupt0(); }
进入Hotspot源码jvm.cpp文件中
再进入os_linux.cpp
然后进入osThread.hpp
进入jvm.cpp中
os_linux.cpp,先复位,再进入jvm.cpp中抛出异常
/* @return <code>true</code> if the current thread has been interrupted; * <code>false</code> otherwise. * @see #isInterrupted() * @revised 6.0 */ public static boolean interrupted() { return currentThread().isInterrupted(true); }
进入os_linux.cpp