Skip to content
Preptima
hardConceptCodingMidSeniorStaff

What does volatile guarantee, and what does it not?

It guarantees visibility and ordering: a volatile write happens-before every later read of that field, so everything the writer did beforehand becomes visible to the reader. It guarantees nothing about atomicity, so an increment is still a race and a volatile reference says nothing about the object it points to.

5 min readUpdated 2026-08-15

Answer

Short answer

volatile in Java guarantees visibility and ordering for one field: a write happens-before later reads of that volatile field. It does not make compound operations atomic, so volatile counters, check-then-act logic and shared mutable objects still need locks, atomics or another coordination mechanism.

Mention java memory model where it changes the risk, the owner, or the next check. A useful java memory model point should make the answer more testable, not merely longer.

Was this answer helpful?

Likely follow-ups

  • Why is the initialisation-on-demand holder idiom usually a better singleton than double-checked locking?
  • What does the final-field guarantee give you that volatile does not?
  • When would LongAdder beat AtomicLong, and why?
  • Does making every field volatile make a class thread-safe?

Related questions

Further reading