Java/Eclipse - Conditional breakpoint and counter?

1.4k Views Asked by At

Is it possible to have a condition on a breakpoint in Eclipse, and have the breakpoint "activate" after that condition has been met n times?

Say for example, in some sloppy mobile-written pseduocode, the breakpoint's condition is:

int n = 0;
If(i == j){
    n++
    If(n > 400)
        true;
}

With i and j being values in my class.

To please the duplicate-hunt, note that I am not asking how to use a conditional statement, I am asking how I can count the number of times a breakpoint condition is met, then have the breakpoint stop my code. Hit does not do this, nor does using a condition in any way I can figure out.

1

There are 1 best solutions below

3
On BEST ANSWER

To activate the breakpoint after the condition is met a certain number of times:

  1. Open breakpoints dialog: Ctrl+double-click breakpoint
  2. Check Conditional checkbox
  3. Use following as condition:

    if (i == j) {
        int n = Integer.parseInt(System.getProperty("breakpoint.n", "0"));
        n++;
        System.setProperty("breakpoint.n", "" + n);
        if (n > 400) return true;
    }
    return false;