I was looking inside the AtomicInteger Class and I came across the following method:
AtomicInteger
/** * Atomically increments by one the current value. *
It's the same thing as
while(true) { //do something }
...just a little bit less clear. Notice that the loop will exit if compareAndSet(current, next) will evaluate as true.
compareAndSet(current, next)
true