你能看一下照片吗?现在,一步前我执行了 this.interrupt()。您可以看到 this.isInterrupted() 为 false。我仔细观察——“这个”没有改变。它具有相同的 ID (12)。那么,为什么interrupt()方法没有结果呢?
稍后添加。代码为文本:
@Override
protected void letUsFinalise() {
this.interrupt();
}
最佳答案
interrupted()
的 javadoc 说:
Tests whether the current thread has been interrupted. The interrupted status of the thread is cleared by this method. In other words, if this method were to be called twice in succession, the second call would return false
(强调我的)
顺便说一句,interrupted()
是一个静态方法。它应该在 Thread 类上调用,而不是在 this
中调用。鉴于它有副作用,您应该在调试器中为其创建一个监视。请观看 isInterruped()
。
关于java - 我怎样才能让interrupt()工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22583540/