volatile
-
java volatile개발 2026. 1. 8. 15:21
아래와 같은 클래스가 있다고 해보자. public static class SharedClass { private int x = 0; private int y = 0; public void increment() { x++; y++; } public void checkForDataRace() { if (y > x) { System.out.println("y > x - Data Race is detected"); } }} x에 대한 증가가 y에 대한 증가보다 먼저 작성되었기 때문에 이론상으로 x>=y 인 상황만 발행해야하고 checkForDataRace 에서 if 문에 걸릴 일은 없다. 그런데 멀티 쓰레..