What Does atomic Mean?
It can be Substantially harder to accidentally violate threadsafety when calling getAndIncrement() than when returning i++ and remembering (or not) to obtain the correct list of monitors beforehand.If you really necessarily mean to make use of a global variable to the atomic, the right (and fastest) code that does what your 1st code block attempts