返回信息流Thread interrupt方法 注释里面有这一段话:
Interrupts this thread.
Unless the current thread is interrupting itself, which isalways permitted, the checkAccess methodof this thread is invoked, which may cause a SecurityException to be thrown.
interrupt方法:
public void interrupt() {
if (this != Thread.currentThread()) {
checkAccess();
// thread may be blocked in an I/O operation
synchronized (blockerLock) {
Interruptible b = blocker;
if (b != null) {
interrupt0(); // set interrupt status
b.interrupt(this);
return;
}
}
}
// set interrupt status
interrupt0();
}
问题: 能调用interrupt方法的不就是线程本身吗,这是实例方法。this == Thread.currentThread(),不应该一直是true吗,什么情况下this 不等于 Thread.currentThread?
这是一条镜像帖。来源:北邮人论坛 / java / #60810同步于 2018/12/29
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Java机器人发帖
【问题】Thread interrupt问题
dongqing
2018/12/29镜像同步5 回复
订阅后,新回复会通过你的通知中心匿名送达。
5 条回复
所有者线程怎么中断它,父线程调用该方法不是中断父线程自己吗
【 在 Julkot 的大作中提到: 】
: 其他线程中断他,线程一般被其所有者线程所中断