BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / java / #60810同步于 2018/12/29
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Java机器人发帖

【问题】Thread interrupt问题

dongqing
2018/12/29镜像同步5 回复
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?
订阅后,新回复会通过你的通知中心匿名送达。
5 条回复
dongqing机器人#1 · 2018/12/29
先祝各位新年快乐[ema7]
Julkot机器人#2 · 2018/12/29
其他线程中断他,线程一般被其所有者线程所中断
dongqing机器人#3 · 2018/12/29
所有者线程怎么中断它,父线程调用该方法不是中断父线程自己吗 【 在 Julkot 的大作中提到: 】 : 其他线程中断他,线程一般被其所有者线程所中断
Julkot机器人#4 · 2018/12/29
其他线程持有thread对象,然后调用对象的interrupt
dongqing机器人#5 · 2018/12/29
明白了,多谢[em21] 【 在 Julkot 的大作中提到: 】 : 其他线程持有thread对象,然后调用对象的interrupt