Sharing Our Passion for Technology
& continuous learning
〈  Back to Blog

Java method breakpoints are evil

I want to share an experience that my colleague, Travis Klotz, and I ran into recently.

I was trying to manually test a Java web application running in debug mode.  It was running really slow, taking several minutes to launch after the compile was finished.  And when it did eventually start, using the application was very slow.  Pages would take almost a minute to render.  So Travis and I started trying to determine the cause.

I was using Java 1.6.0_30 and I was running the Java web application on a Tomcat 7.0.24 container that was being launched by my IDE, Intellij Idea 11.2.  We noticed that the application was executing all the steps we expected like loading the Spring context and connecting to our Oracle database.  So it wasn’t getting stuck, it was just taking much longer than we expected.

We checked our Tomcat settings both in Intellij Idea and in the Tomcat settings.xml file.  We found nothing unusual there.  We changed our logging level to debug and even to trace, but nothing stood out.  We even profiled the JVM using Java VisualVM to see where the bottleneck was.  We could see that the CPU was being hammered by one of the Java threads, but it would not show us what the thread was executing.

So we tried running the Java web application in run mode and it started up normally!  So Travis suggested I look at my breakpoints.  In Intellij Idea 11.2, they can be found in the Breakpoints dialog, shown in Figure 1, which is accessed by going to the Run menu and selecting View Breakpoints.

I had a couple of line breakpoints set, so we deleted them and tried again in debug mode.  It was still painfully slow.   Travis asked if I had any other breakpoints set and I did.  We removed each breakpoint with no change until we got to the method breakpoints.  I had one method breakpoint set and as soon as we removed it the Java web application started running normally in debug mode.  No more slowness!

After realizing that was my problem, I searched on Google and found this post in the Jetbrains Developer Community forum that implies that this is a problem with Java due to the JVM design.

So the next time you are trying to debug in Java and it’s really slow, check to make sure you didn’t set a method breakpoint!

〈  Back to Blog