Atomic Operation

Atomic operation make sure that the operation can only be execute in a single thread at a time.

For example

private final AtomicInteger capacity;
capacity.incrementAndGet(); // this can only be executed 
							// within 1 thread.

However if we have multiple atomic operations, it's not guaranteed to be all executed in a single thread .

For example

private void incrementEnd() {
  capacity.incrementAndGet();
  if (end.incrementAndGet() == storage.length) {
    end.set(0);
  }
}

This is not always guaranteed to be thread-safe