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:
Initializing jdb ...
> stop in PrimeNumberSeeker.main
Deferring breakpoint PrimeNumberSeeker.main.
It will be set after the class is loaded.
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 stop in PrimeNumberSeeker.run
Set breakpoint PrimeNumberSeeker.run
Period, Current int, # primes
1, 2, 0
Breakpoint hit: "thread=Thread-0", PrimeNumberSeeker.run(), line=28
28 primes = new int[ceiling];
(java.lang.ref.Reference$ReferenceHandler)0x157 Reference Handler...
(java.lang.ref.Finalizer$FinalizerThread)0x156 Finalizer ...
(java.lang.Thread)0x155 Signal Dispatcher...
(java.lang.Thread)0x154 Attach Listener ...
(java.lang.Thread)0x1 main sleeping
(PrimeNumberSeeker)0x189 Thread-0 running (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" to "Thread-0".
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.
Last update: 2015.
Table of Contents
About This Book
Java Tools Terminology
Installing Java 8 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 a 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
jvisualvm (Java VisualVM) - JVM Visual Tool
'jar' - The JAR File Tool
'javap' - The Java Class File Disassembler
'keytool' - Public Key Certificate Tool
'native2ascii' - Native-to-ASCII Encoding Converter
PDF Printing Version