Conditional Breakpoints and Multi Thread Debugging with JDeveloper 10g
Conditional Breakpoints and Multi Thread Debugging with JDeveloper 10g
Written by Olivier Le Diouris, Oracle Corporation
March 2004.
We are going to explain how to debug a multithreaded java application, using the convenient conditional
breakpoints you can set in JDeveloper 10g.
The code
We are going to illustrate our point with a very simple application.
Here is its code.
To run it from JDeveloper, you have to allow some input from the user. To do so, go to
Project Properties | Runner | Options, and check the box labeled "Allow Program Input".
Then you can run your application, and you can enter the required values in the input field at the bottom of the log window.
Once you've stopped all the threads, the application exits normally.
Debug
Now, we want to debug our application. Let us say we want to investigate what's going on in the
doYourJob method. Let us set a breakpoint in it.
And now, let us start the debugger. Everytime a thread calls the doYourJob method, we hit the breakpoint, which
is the expected behavior.
Set your Conditional Breakpoints
This behavior is fine, but for some reason, we might want to see what's going on only for a given thread,
like let us say the first one we've started.
We have in JDeveloper 10g the possibility to set this kind of condition on a break point. Right click on your breakpoint in the
gutter of the code pane, and select "Edit Breakpoint".
Go to the second tab
Select the second radio button
And give the name of the thread you want to stop on.
Also, you can right click on the header of the table in the breakpoints window,
to change the columns displayed, to see the name of the thread you're in:
And from now on, whenever you're stoppped at the breakpoint, it is only if you're calling it from the
thread named "ThreadOne". Notice that you don't have to end the debugging session to set conditions on
an existing breakpoint (or to create a new one, actually).
Even better, if the context you want to track from the debugger is only there after hitting the
breakpoint a certain number of times, you can break on it after hitting it let's say 15 times:
Then you will stop at the breakpoint after it has been met 15 times (or more) from the given thread.
And in case you need it, you can set your own kind of complex condition in the same dialog box...
In addition, you also have the possibility to state you own condition for the breakpoint in Java, in the
dedicated field, labeled "Condition".
This condition - which can be combined with the other ones - must express a boolean, evaluated by the debugger, which will stop on the break point when it is true.
Today, Strings operations, and comparisons between scalars are supported.
Basically, whatever is supported in the Watch window as a boolean can be used as a Condition.
The watches can be used to compute values, evaluated when a breakpoint is hit.