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

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.

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