intellij - not stopping on all breakpoints in multithreaded code intellij - not stopping on all breakpoints in multithreaded code multithreading multithreading

intellij - not stopping on all breakpoints in multithreaded code


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.


I just had this problem and for the sake of others that run into this, here is the reason for this behavior and how to change it.

As Doron pointed out, there is documentation concerning this. However, the IMPORTANT thing to notice is that by default, all threads in the JVM are suspended when a breakpoint is reached.

What you are expecting (and what I was expecting) is that only the thread with the breakpoint is suspended.

This isn't what you want, nor is it what I wanted.

To change this behavior (and provide the desired behavior).

1) Create a breakpoint by left clicking in margin.
2) Press ctrl+shift+F8 (to bring up the breakpoint menu).
3) Select your breakpoint. You will see options for it.
4) Make sure "Suspend" is checked and "Thread" radio option is selected.
5) Click the "Make default" button.

Now, when you run, you'll see that breakpoints in different threads are hit.


Because the other thread is scheduled to run in the background, and when the OS thread scheduler decides to run it, it will run. When you do have a breakpoint in it, it will be hit.

It won't have started necessarily when you just run through the code, so the breakpoint at i++ is hit immediately.