interrupt相关函数
interrupt()
描述:给线程添加一个中断标识,但是不影响线程的执行。
/**
* 中断线程
*/
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();
}
isInterrupted(boolean ClearInterrupted)
描述:本地方法,用于判断线程是否中断。
/**
* 本地方法
* @param ClearInterrupted 是否清除中断标识
*/
private native boolean isInterrupted(boolean ClearInterrupted);
interrupted()
描述:检查当前线程是否中断,并且清除中断标识。这个函数是一个静态方法,调用当前线程的isInterrupted()方法。
/**
* 检查线程是否中断,并且清除中断标识
*/
public static boolean interrupted() {
return currentThread().isInterrupted(true);
}
isInterrupted()
描述:检查线程是否中断,不清除中断标识
public boolean isInterrupted() {
return isInterrupted(false);
}