我正在尝试使用断点运行以下代码,如下所示:
new Thread(new Runnable() {
@Override
public void run() {
System.out.println("Starting"); //breakpoint here
}
}).start();
int i = 10;
i++; //breakpoint here
当此代码仅运行时,将击中i++断点...如果我删除了该断点,则将正确命中另一个线程的断点。为什么会发生这种奇怪的行为?
最佳答案
记录在http://www.jetbrains.com/idea/webhelp/breakpoints-2.html中:
There are certain cases when IntelliJ IDEA will not stop at a breakpoint. Consider the following situation: Two breakpoints are set at the different methods of a class, and there suspend policy is set to All. When one of the breakpoints is hit, some step actions are performed. If at the time of stepping another thread hits the second breakpoint, IntelliJ IDEA will not stop there.
我复制了您的代码示例并重新创建了这种情况。
确实,如文档中所述,在
i++
断点处停止后,如果我按F8键(跨步),则程序不会在另一个断点处停止。但是,如果我按F9键(恢复),则程序会使在另一个断点处再次停止。
关于multithreading - intellij-不在多线程代码中的所有断点上停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15298662/