由于未知原因,我无法从Intellij IDEA评估表达式窗口中获取currentThread().isInterrupted()的正确值.
这是一个小代码段,将帮助您重现相同的行为:
public class IsInterruptedTest {
public static void main(String[] args) {
Thread.currentThread().interrupt();
System.out.println(Thread.currentThread().isInterrupted());
}
}
要重现它,请执行以下步骤:
>在System.out.println(Thread.currentThread().isInterrupted())处设置断点;
>在调试模式下启动主要方法
>等待执行到断点.
>调用Thread.currentThread().isInterrupted();从“评估表达式”窗口(Alt F8). (对我来说,此调用返回假值)
>恢复程序执行,完成后-检查控制台中打印的值. (对我来说,这里印有true)
所以,我的问题是-为什么这两个值不同?
这是由于调试器正在挂起当前线程而发生的吗?如果是这样,是否有任何方法可以从IDE中的“评估表达式”窗口中获取isInterrupted()调用的正确值?