为什么线程中的这两个值相等?

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);
        }

    }
}

为什么输出的值相等,并且只出现一次
在这里插入图片描述

发布了23 篇原创文章 · 获赞 1 · 访问量 3149

猜你喜欢

转载自blog.csdn.net/qq_43669912/article/details/95235978