∟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.