Example: Running the Hanoi Sample with a Breakpoint Set (Integrated Debugger)

Objective
Demonstrate suspending a running sample by setting a breakpoint.

Time Required
10 Minutes

Before You Start
Add the Hanoi Sample to the workspace if it is not already there.  In the repository, it is located in the project IBM Java Examples, in the package com.ibm.ivj.examples.hanoi.

Instructions
To set the breakpoint where it will suspend the program repeatedly:

  1. Open a Class browser on the com.ibm.ivj.example.hanoi.Hanoi class.
  2. Select the com.ibm.ivj.example.hanoi.Hanoi.moveDisk(Post,Post) method.
  3. In the Source for the moveDisk method, set a breakpoint on the following line:
    destination.addDisk(source.removeDisk());

    Set it by placing the cursor somewhere in the line and selecting Breakpoint from the Edit menu, or by double-clicking on the left-hand margin next to the line.

Then run the application class, Hanoi.  The Debugger browser will open the first time the program encounters the breakpoint.  Step through the method.  The Console window will show that the disk is moved from one post to the other as you step.  

Click the Resume button resume.gif (1020 bytes).   The program will again run until it encounters the breakpoint again - when it is about to move another disk.

To finish running the program, without stopping at breakpoints:

  1. Click on the Breakpoints tab in the Debugger browser
  2. Click the Disable/Enable Breakpoints button bp_off.gif (1006 bytes) in the toolbar. 
  3. Click the Debug tab.
  4. Click the Resume button resume.gif (1020 bytes) in the toolbar.

The program will run to the end, solving the Tower of Hanoi problem.