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

Starting Debugging Session on a Multi-Thread Application

This section provides a tutorial example on how to start a debugging session on a multi-thread Java application, PrimeNumberSeeker.java.

1. Setting up breakpoints and getting the debugging session going:

C:\herong>jdb PrimeNumberSeeker

Initializing jdb ...
> stop in PrimeNumberSeeker.main
Deferring breakpoint PrimeNumberSeeker.main.
It will be set after the class is loaded.

> run
run PrimeNumberSeeker
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
>
VM Started: Set deferred breakpoint PrimeNumberSeeker.main

Breakpoint hit: "thread=main", PrimeNumberSeeker.main(), line=13 
13          System.out.println("Period, Current int, # primes");

main[1] stop in PrimeNumberSeeker.run
Set breakpoint PrimeNumberSeeker.run

main[1] cont
Period, Current int, # primes
1, 2, 0
>
Breakpoint hit: "thread=Thread-0", PrimeNumberSeeker.run(), line=28
28          primes = new int[ceiling];

Thread-0[1] threads
Group system:
  (java.lang.ref.Reference$ReferenceHandler)0xe2 Reference Handler
  (java.lang.ref.Finalizer$FinalizerThread)0xe1  Finalizer        
  (java.lang.Thread)0xe0                         Signal Dispatcher
Group main:
  (java.lang.Thread)0x1         main          running
  (PrimeNumberSeeker)0x118      Thread-0      running (at breakpoint)

Ok. What I have done so far:

  • Started the debugging session with the first breakpoint at the beginning of the main() method, which cause the execution to stop at line 13.
  • Then I created the second breakpoint at the beginning of the run() method in order to catch the sub thread.
  • Then I issued the "cont" command. My application continued with the sub thread created stopped at the breakpoint at line 28. The main thread also stopped.
  • Noticed that the debugger prompt is changed from "main[1]" to "Thread-0[1]". This is to inform you that you are currently in the sub thread, no longer in the main thread.
  • Then I used the "threads" command to list all threads. I saw two thread groups: "system" and "main". Of course, I am not interested in the "system" group at this point. The "main" shows two threads: "main" (my monitoring thread) and "Thread-0" (my sub thread working on the calculation).
  • Thread "Thread-0" status shows "running (at breakpoint)". But the word "running" is referring to the thread execution mode, not the current execution status.
  • Notice that tread "main" is also stopped at this moment. As a general rule, if one thread is stopped, all other threads are stopped also.

Table of Contents

 About This Book

 Java Tools Terminology

 Installing J2SE 1.6.0 on Windows

 Installing J2SE 1.5.0 on Windows

 'javac' - The Java Program Compiler

 'java' - The Java Program Launcher

'jdb' - The Java Debugger

 '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

 'jconsole' - Java Monitoring and Management Console

 'jstat' - JVM Statistics Monitoring Tool

 JVM Troubleshooting Tools

 'jar' - The JAR File Tool

 'javap' - The Java Class File Disassembler

 'keytool' - Public Key Certificate Tool

 'native2ascii' - Native-to-ASCII Encoding Converter

 References

 PDF Printing Version

Dr. Herong Yang, updated in 2008
Starting Debugging Session on a Multi-Thread Application