There would be a difference if you reassign the variable: atomicInteger = new AtomicInteger()
in a method, in which case marking the variable as volatile
will guarantee that the assignment will be visible by other threads.
But if you only use the AtomicInteger
instance that is created with each instance of your class and never reassign it, then volatile
is unnecessary.