I read somewhere below line.
Java volatile keyword doesn't means atomic, its common misconception
that after declaring volatile,operation will be atomic, to make
the operation atomic you still need to ensure exclusive access using
method or block in Java.
The effect of the
volatile keyword is approximately that each individual read or write operation on that variable is atomic.
Notably, however, an operation that requires more than one read/write -- such as
i++, which is equivalent to
i = i + 1, which does one read and one write -- is not atomic, since another thread may write to
i between the read and the write.
Atomic classes, like
AtomicReference, provide a wider variety of operations atomically, specifically including increment for