Dear Ranchers,
Below from Sun free assesment :
class NoGo implements Runnable {
private int i;
public synchronized void run () {
if (i%10 !=0) {i++;}
for (int x=0;x<10;x++,i++) {
if (x==4) Thread.yield();
}
System.out.println (i+" ");
}
public static void main (
String[] args) {
NoGo n = new NoGo ();
for (int x=0;x<101;x++) {
new
Thread (n).start();
}
}
}
When I compile above code, it gives me output value from 10 to 1010. Could somebody help me to understand how this code works, please? and thanks for your reply.
regards,
-Mila-