[concurrency-interest] AtomicLong vs AtomicLongFieldUpdater addAngGet

Patrick Julien pjulien at gmail.com
Sat Sep 5 07:41:39 EDT 2015

In Java 8, AtomicLong and AtomicInteger were modified to use the new
unsafe operations, e.g.,

public final long addAndGet(long delta) {
    return unsafe.getAndAddLong(this, valueOffset, delta) + delta;

but not the field updater variants which still do a compare and set

public long addAndGet(T obj, long delta) {
    long prev, next;
    do {
        prev = get(obj);
        next = prev + delta;
    } while (!compareAndSet(obj, prev, next));
    return next;

Is there any reason for this or is it just an omission?

More information about the Concurrency-interest mailing list