Advanced Java Debugging Techniques: Conditional Breakpoints, Drop Frame, Multithreaded and Remote Debugging
This article explains practical Java debugging tricks such as setting conditional breakpoints, using Drop Frame to revisit previous execution points, handling multithreaded breakpoints, configuring remote debugging, and evaluating or modifying expressions on the fly to streamline development and troubleshooting.
Conditional Breakpoints – When iterating over a large list, you can pause execution at a specific value by right‑clicking the breakpoint’s red dot, selecting Condition , and entering an expression like i == 10 . The debugger will stop only when the condition is true.
Return to "Previous Step" (Drop Frame) – In complex call stacks, you can drop the current stack frame to return to an earlier method call. After hitting a breakpoint inside method2 , click the Drop Frame icon (red arrow) to move the execution pointer back to method1 , restoring variable values as they were at that point.
Multithreaded Debugging – Threads may hit breakpoints unpredictably. To control which thread pauses, right‑click each breakpoint’s red dot and set the Suspend policy to Thread instead of All . Then you can select a specific thread (e.g., “Sky Bird”) from the dropdown to ensure the breakpoint stops exactly where you need it.
Remote Debugging
1. Enable remote debugging when starting the JVM: java -server -Xms512m -Xmx512m -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9081 -Djava.ext.dirs=. ${main_class}
The crucial part is the -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9081 options, which open a socket for the IDE to attach. Ensure the port does not conflict and that the local machine can reach the remote host.
2. In IntelliJ IDEA, add a Remote configuration, specify the host and port (e.g., 9081), and start the session. Once connected, you can set breakpoints in the source code and debug the remote application as if it were running locally.
Evaluating Expressions / Modifying Variable Values – While paused, click the Evaluate Expression (or the plus icon) to type an expression such as i + 5 and press Enter to see the result instantly. To change a variable’s value, right‑click the variable in the Watches or Variables pane, choose Set Value , and enter the new value.
Using these debugging techniques can greatly improve productivity and code comprehension during development.
Architect's Tech Stack
Java backend, microservices, distributed systems, containerized programming, and more.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.