'jdb' - The Java Debugger
Part:
1
2
3
4
5
6
7
8
9
(Continued from previous part...)
What I have done here:
- I used "next" again. The sub thread jumped over the calculation loop between line 33 and 36.
This is correct, since "current" has "3", a prime number, no need to do any calculation.
- Then I used "next" and "print" several times. I saw prime number 3 was correctly recorded
in the "primes" array.
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.
5. Switching threads:
main[1] cont
>
Breakpoint hit: "thread=main", PrimeNumberSeeker.main(), line=19 bci=25
19 System.out.println( i+", "+t.current+", "+t.count);
main[1] print t.current
t.current = 14
main[1] print t.count
t.count = 6
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] threads
...
Group main:
(java.lang.Thread)0x1 main running
(PrimeNumberSeeker)0x118 Thread-0 running (at breakpoint)
main[1] thread 280
Thread-0[1] list
Current method is native
Thread-0[1] step out
11, 22, 8
>
Step completed: "thread=Thread-0", PrimeNumberSeeker.run(), line=45
45 }
Thread-0[1] list
41 try {
42 sleep(delay);
43 } catch (InterruptedException e) {
44 System.out.println("Runner interrupted.");
45 => }
46 }
47 }
48 }
Thread-0[1] print count
count = 8
(Continued on next part...)
Part:
1
2
3
4
5
6
7
8
9
|