public class X implements Runnable {
private int x;
private int y;
public static void main(String[] args) {
X that = new X();
(new Thread(that)).start();
(new Thread(that)).start();
}
public synchronized void run() {
for (;;) {
x++;
y++;
System.out.println("x=" + x + ",y=" + y);
}
}
}
为什么输出的值相等,并且只出现一次