if a long variable is declared as :-
private volatile long counter = 0;
now if i increment it using pre-increment operator, then would the operation be atomic ?
if yes, then will it be more efficient than java.util.concurrent.atomic.AtomicLong object’s increment ??
volatilekeyword only solves visibility problem. You have to useAtomicLongorsynchronizedmethod/block for atomicity (Atomicity in concurrent programming).One more article that came out today: Demonstrating when volatile is required