Sign up ×

I know why to use synchronization in Java, but I can´t find answer on this question:

do I need to synchronized an atomic operation?

If yes, why?

share|improve this question

closed as not a real question by Jack Maney, Danubian Sailor, Sean Owen, Tim Bish, Zak Apr 22 '13 at 22:52


If you know why to use synchronization in Java, then you should be able to answer your own question. Think about what it means for an operation to be atomic. – Sotirios Delimanolis Apr 22 '13 at 21:26

3 Answers 3

up vote 4 down vote accepted

If it really is atomic, then no.

You need synchronization to provide coherent state. Any atomic operation results in cohernt state by definition of being atomic.

share|improve this answer

There are very few truly atomic operations in Java. From the Atomic Access Java Tutorial:


Note that synchronization is not just used for mutual exclusion, but it's also required for reliable communications between threads. Even when you're dealing with data that is atomically readable and writable, there's no guarantee when, if ever, one thread will see a change made by another. For this reason you need to either synchronize access to shared data, or make sure shared variables are declared volatile.

share|improve this answer

You need to be sure that your atomic operation does not expand to multiple read and update operations. Simple expressions like the increment and decrement operations do expand into multiple actions thus i++ and i-- are not atomic operations. Thus most times if you are reading and updating variable from multiple threads then you are better off using a synchronized methods.

More Details:

share|improve this answer
