Search code examples
multithreadingintellij-ideabreakpoints

intellij - not stopping on all breakpoints in multithreaded code


I am trying to run the following code with break points as follows:

    new Thread(new Runnable() {
        @Override
        public void run() {
            System.out.println("Starting"); //breakpoint here
        }
    }).start();

    int i = 10;
    i++; //breakpoint here

when this code runs ONLY the i++ breakpoint is hit... If I remove that one, the other thread's breakpoint would be hit correctly. Why is this weird behaviour occuring?


Solution

  • This is documented in 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 copied your code example and recreated the situation. Sure enough, like it says in the documentation, after stopping at the i++ breakpoint, if I hit F8 (step over) the program doesn't stop on the other breakpoint. But if I hit F9 (resume) the program does stop again on the other breakpoint.