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

Debugging the Main Thread of a Multi-Thread Application

This section provides a tutorial example on how to debug the main thread of a multi-thread application.

4. Going back to the main thread:

Thread-0[1] stop at PrimeNumberSeeker:19
Set breakpoint PrimeNumberSeeker:19
Thread-0[1] cont
>
Breakpoint hit: "thread=main", PrimeNumberSeeker.main(), line=19 bci=25
19             System.out.println( i+", "+t.current+", "+t.count);

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

main[1] print i
 i = 11

main[1] print t.current
 t.current = 3

main[1] print t.count
 t.count = 1

What I have done here:

  • I created another breakpoint in the main thread at line 19.
  • Then I allowed both threads to run naturally to the next breakpoint, line 19. The command prompt is changed back to "main[1]".
  • Then I used "where all" to check where the execution are stopped in all threads. It is interesting to see that the sub thread stopped inside the sleep() method.
  • Then I checked some local variables, "i", "t.current", and "t.count". Their values were all correct.

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
Debugging the Main Thread of a Multi-Thread Application