In the following code the output could be
1 --- 0,2,4,6,8,10,12,14,
2 --- 0,2,4,6,0,2,4,6,
3 --- 0,0,2,2,4,6,4,6,
4 --- 0,0,2,2,4,4,6,6,
5 --- 0,0,2,4,6,2,4,6,
and many more it could be.
public class Thread1 {
int x = 0;
public class Running implements Runnable {
public void run() {
int count = 0;
for (int i = 0; i < 4; i++) {
count = x;
System.err.print(count + ",");
x = count + 2;
}
}
}
public static void main(String[] a) {
new Thread1().go();
}
private void go() {
Runnable r11 = new Running();
new Thread(r11).start();
new Thread(r11).start();
}
}
This is what Thread is ...
bcoz two threads are created and they are accessing the run method at same time.
Thanks. If any mistake pls Rectify.