5.9. Setting a Hit Count for Breakpoints
Problem
You want to break only after a breakpoint has been encountered a specified number of times.
Solution
Breakpoints can be enabled after a specified number of hits, called a
hit count. To set a
breakpoint’s hit count, right-click the breakpoint
in the Breakpoints view and click Properties, opening the Java Line
Breakpoint Properties dialog. Check the “Enable Hit
Count” checkbox, and enter the hit count you want.
Discussion
You can see an example in Figure 5-16, in which the hit count of a breakpoint is set to 3.

Figure 5-16. Setting a breakpoint hit count
Click OK to close this dialog, and then restart the debugging session (you can end the session by clicking the Terminate button, or by selecting Run→ Terminate and starting the debugging session again). When you do, execution will be suspended the third time that breakpoint is encountered.
Tip
You also can set a breakpoint’s hit count by right-clicking the breakpoint in the Breakpoints view, clicking Hit Count, and entering the hit count you want in the dialog that opens.
See Also
Recipe 5.10 on configuring breakpoint conditions.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access