int j = 0; for (int i = 0; i < 2; i++) {new Thread(new Runnable(){ protected void run() { j++;} }).start(); new Thread(new Runnable(){ protected void run() { j--; } }).start(); }
public class TestThreadSimple { static int j; public static void main(String[] args) { for (int i = 0; i < 2; i++) { new Thread(new Runnable(){ public void run() { System.out.println(j++);} }).start(); new Thread(new Runnable(){ public void run() { System.out.println(j--); } }).start(); } }}
for (int i = 0; i < 2; i++) {new Thread(new Runnable(){ protected void run() { j++;} }).start();
new Thread(new Runnable(){ protected void run() { j--; } }).start();
}
public static void main(String[] args) {
for (int i = 0; i < 2; i++) { new Thread(new Runnable(){ public void run() { System.out.println(j++);} }).start();
new Thread(new Runnable(){ public void run() { System.out.println(j--); } }).start();
}
}}