Can someone explain why he is not working here? Since I was declared volatile, it should be protected from memory mismatch.
, , , i++ . //. volatile . :
- # 1
i, 10 - , # 2
i, 10 - # 1
i 11 - # 2
i 11 - thread # 1 11
i - thread # 2 11
i
, , 2 , , , 1. . . : volatile int Java?
, , - AtomicInteger, .
static final AtomicInteger i = new AtomicInteger(0);
...
for (int j = 0; j<1000000; j++) {
i.incrementAndGet();
}