36

If I have two threads running concurrently in my program and put a breakpoint on one of them, will the other thread stop also halt when this breakpoint is hit, or will it continue executing regardless?

(I am writing in Java and using NetBeans)

CJBS
  • 15,147
  • 6
  • 86
  • 135
Eamonn McEvoy
  • 8,876
  • 14
  • 53
  • 83
  • 4
    @mre well as you can see from mijer's answer it depends on the environment settings, so my observations were not giving me the full picture and therefore this question was worth asking. – Eamonn McEvoy Nov 17 '11 at 23:17

4 Answers4

39

Breakpoints have an option how they should behave: to suspend a single thread or all threads

breakpoints

szhem
  • 4,672
  • 2
  • 18
  • 30
  • Can't speak to other IDEs, but In IDEA you can right-click on a breakpoint in the gutter and change its Suspend Mode from "All" (the default) to "Thread." I did not know you could do this until today when I was trying to figure out why a breakpoint in a Guava event bus handler was suspending the main thread. – joshbodily Feb 20 '15 at 17:25
9

I believe that each thread will stop once it hits the breakpoint in the code, while other threads will continue to run. I remember this from my Tomcat days.

Naftuli Kay
  • 87,710
  • 93
  • 269
  • 411
  • If we are talking about single web app, I think this is likely not true. In intellij idea breakpoint by default stops all threads. Because of this I had difficulties, trying to debug @Async: I didn't work in debug as I expected – divideByZero May 28 '16 at 14:39
2

It might be interesting to note that in Eclipse and NetBeans the default behavior is to suspend the current thread when the breakpoint is hit, while in IntelliJ it suspends all threads.

1

By default only the thread that hits the breakpoint stops. However, you can modify the behavior by changing the breakpopint properties.

sixtytrees
  • 1,156
  • 1
  • 10
  • 25