Курс многопоточности в Java

Синхронизация потоков

1/9

Каков результат выполнения кода?

class MyRunnable implements Runnable {
    private int x, y;

    public void run() {
        for (int i = 0; i < 500; i++) {
            synchronized (this) {
                x = 15;
                y = 15;
            }
        }
        System.out.print(x + " " + y + " ");
    }

    public static void main(String[] args) {
        MyRunnable run = new MyRunnable();
        Thread t1 = new Thread(run);
        Thread t2 = new Thread(run);
        t1.start();
        t2.start();
    }
}
Comments