Java Tool Tutorials - Herong's Tutorial Notes
Dr. Herong Yang, Version 5.00

Stepping through Statements of the Child Thread

This section provides a tutorial example on how to step through execution statements of the child thread in a multi-thread application.

2. Stepping through statements in the sub thread:

Thread-0[1] where all
Signal Dispatcher:
Finalizer:
  [1] java.lang.Object.wait (native method)
  [2] java.lang.ref.ReferenceQueue.remove (ReferenceQueue.java:111)
  [3] java.lang.ref.ReferenceQueue.remove (ReferenceQueue.java:127)
  [4] java.lang.ref.Finalizer$FinalizerThread.run (Finalizer.java:...
Reference Handler:
  [1] java.lang.Object.wait (native method)
  [2] java.lang.Object.wait (Object.java:429)
  [3] java.lang.ref.Reference$ReferenceHandler.run (Reference.java...
main:
  [1] java.lang.Thread.sleep (native method)
  [2] PrimeNumberSeeker.main (PrimeNumberSeeker.java:21)
Thread-0:
  [1] PrimeNumberSeeker.run (PrimeNumberSeeker.java:28)

Thread-0[1] next
2, 2, 0
>
Step completed: "thread=Thread-0", PrimeNumberSeeker.run(), line=29
29          while (count < ceiling) {

Thread-0[1] where all
...
main:
  [1] java.lang.Thread.sleep (native method)
  [2] PrimeNumberSeeker.main (PrimeNumberSeeker.java:21)
Thread-0:
  [1] PrimeNumberSeeker.run (PrimeNumberSeeker.java:29)

Thread-0[1] next
3, 2, 0
>
30             current++;

Thread-0[1] next
4, 3, 0
>
31             int j = 2;

Thread-0[1] next
> 5, 3, 0
32             boolean isPrime = true;

Thread-0[1] next
6, 3, 0
>
33             while (j<current/2 && isPrime) {

Thread-0[1] list
29          while (count < ceiling) {
30             current++;
31             int j = 2;
32             boolean isPrime = true;
33 =>          while (j<current/2 && isPrime) {
34                isPrime = current % j > 0;
35                j++;
36             }
37             if (isPrime) {
38                count++;
Thread-0[1] print current
 current = 3

What I have done here:

  • I used "where all" to display the current location of all threads.
  • Then I used "next" to execute one statement in the current thread, the sub thread, going from line 28 to line 29.
  • The next "where all" command showed me that the main thread went through an entire iteration of the "while" loop. The main thread stopped again at line 21.
  • Then I used a couple of "next" command in the sub thread to bring the execution to line 33. At the same time, the main thread went through a couple of iterations, printed some output messages.
  • Then I used "print" to check the current value of variable "current". Value 3 is correct.

Sections in This Chapter

'jdb' - Java Debugger Command and Options

Starting a Debugging Session with 'jdb'

Debugging Applications with Separate 'jdb' Sessions

Debugging Java Applications Remotely

Listing Debugging Commands with 'help' Command

PrimeNumberSeeker.java - Multi-Thread Sample Program

Starting Debugging Session on a Multi-Thread Application

Stepping through Statements of the Child Thread

Checking Variable Values in a Debugging Session

Debugging the Main Thread of a Multi-Thread Application

Switching Execution Threads in a Debugging Session

Suspending Main Thread to Debug Child Thread

Dr. Herong Yang, updated in 2008
Stepping through Statements of the Child Thread