'jdb' - The Java Debugger
Part:
1
2
3
4
5
6
7
8
9
(Continued from previous part...)
Thread-0[1] next
> 5, 3, 0
32 boolean isPrime = true;
Thread-0[1] next
6, 3, 0
>
33 while (j<current/2 && isPrime) {
Thread-0[1] list
29 while (count < ceiling) {
30 current++;
31 int j = 2;
32 boolean isPrime = true;
33 => while (j<current/2 && isPrime) {
34 isPrime = current % j > 0;
35 j++;
36 }
37 if (isPrime) {
38 count++;
Thread-0[1] print current
current = 3
What I have done here:
- I used "where all" to display the current location of all threads.
- Then I used "next" to execute one statement in the current thread, the sub thread, going from line 28
to line 29.
- The next "where all" command showed me that the main thread went through an entire iteration of the
"while" loop. The main thread stopped again at line 21.
- Then I used a couple of "next" command in the sub thread to bring the execution to line 33. At the
same time, the main thread went through a couple of iterations, printed some output messages.
- Then I used "print" to check the current value of variable "current". Value 3 is correct.
3. Checking local variables:
Thread-0[1] next
7, 3, 0
>
37 if (isPrime) {
Thread-0[1] print isPrime
isPrime = true
Thread-0[1] next
8, 3, 0
>
38 count++;
Thread-0[1] next
9, 3, 0
>
39 primes[count-1] = current;
Thread-0[1] print count
count = 1
Thread-0[1] next
> 10, 3, 1
42 sleep(delay);
Thread-0[1] list
38 count++;
39 primes[count-1] = current;
40 }
41 try {
42 => sleep(delay);
43 } catch (InterruptedException e) {
44 System.out.println("Runner interrupted.");
45 }
46 }
47 }
Thread-0[1] print primes[0]
primes[0] = 3
(Continued on next part...)
Part:
1
2
3
4
5
6
7
8
9
|