Exercise 3: Examining Threads

In this exercise, you will view the thread groups, threads, and stack frames that make up the project. You will also learn how to track the changes in variable values as the program progresses.
  1. Bring the Debugger's Thread/Stack tab to the front.
    The Blink project includes three thread groups: main, sun.applet.AppletViewer.main, and applet-Blink.class. The main thread group includes threads that run in the browser. The sun.applet.AppletViewer.main thread group includes threads that run in the Applet Viewer. The applet-Blink.class thread group contains threads directly related to the Blink project. Each thread group is accompanied by the glyph.

    Both the sun.applet.AppletViewer.main and applet-Blink.class thread groups contain two threads. Two of these threads are open to show the call stack that makes up the thread.

  2. Look at the second thread under the second thread group, sun.applet.AppletViewer.main.
    You'll see a line similar to:

    "AWT-Motif" (java.lang.Thread) at breakpoint (priority 5)

    On Windows NT and Windows 95, you will see a different thread class name such as AWT-Callback-Win32. In the above line:

    The glyph accompanying a thread is an additional clue as to the state of the thread. In this tab you'll see , which indicates a thread is suspended and , which indicates a thread is stopped at a breakpoint. In all, a thread can be in one of seven states.

  3. Look at the call stack that makes up the AWT-Motif or AWT-Callback-Win32 thread class.
    The call stack includes all the methods that have been called but have not returned. Blink.paint, which was executing when the program stopped, is at the top of the stack. The stack frame is highlighted so you can easily tell where the program stopped. The initial method is at the bottom of the stack. Each stack frame is accompanied by the glyph.

  4. Click the glyph to the left of Blink.paint.
    The WorkShop shows the variables and their current values local to Blink.paint. Look at the variable word (variable [12]). The value is Java.

  5. Click the Resume All button at the bottom of the Threads/Stack tab.
    The program runs through the loop and stops when it hits the breakpoint a second time. The Source Editor fronts and the Threads/Stack display is updated. Move the Source Editor so you can see that the value of word in the Threads/Stack tab is now WorkShop.

  6. Click the Resume All (on either the Source Editor or Threads/Stack tab) several more times.
    In the Threads/Stack tab, track the changes in word as the program progress through the loop. The value cycles through "Java WorkShop is really cool :-)."

  7. Click the glyph to the left of the this object.
    The WorkShop expands the object to show all embedded variables within the object. You can repeat this action on nested objects (for example, peer).

  8. Click to the left of the this object a second time.
    The WorkShop contracts the object.

Next lesson:

Exercise 4: Stepping Through a Method