Q&A
Q&AWhen should you use volatile, synchronized, or AtomicInteger?
Choose based on whether you need visibility, mutual exclusion, or atomic operations on one value.
Read the concise answer
Volatile gives visibility and ordering for a field but does not make compound read-modify-write operations atomic. Synchronized protects a critical section and its invariants using a monitor. AtomicInteger provides atomic operations such as increment-and-get for one integer; it does not make a group of fields update transactionally.