Given:
5. class NoGo implements Runnable {
6. private static int i;
7. public synchronized void run() {
8. if (i%10 != 0) { i++; }
9. for(int x=0; x<10; x++, i++)
10. { if (x == 4) Thread.yield(); }
11. }
12. public static void main(String [] args) {
13. NoGo n = new NoGo();
14. for(int x=0; x<101; x++) {
15. new Thread(n).start();
16. System.out.print(i + " " );
17. } } }
Which is true?
A The output can never contain the value 10.
B The output can never contain the value 30.
C The output can never contain the value 297.
D The output can never contain the value 820.
E Making the run method un-synchronized will not change the possible output.
resultado :
0 0 0 0 0 0 4 4 4 4 4 4 14 14 14 14 14 14 24 24 24 24 24 24 34 34 34 34 34 34 44 44 44 44 44 44 54 54 54 64 64 64 64 64 64 74 74 74 74 74 74 84 84 84 84 84 84 94 94 94 94 94 94 104 104 104 104 104 104 114 114 114 114 114 114 124 124 124 124 124 124 134 134 134 134 134 134 144 144 144 144 144 144 154 154 154 154 154 154 164 164