When in doubt, you may look into implementation:
public final int accumulateAndGet(int x, IntBinaryOperator accumulatorFunction) { int prev, next; do { prev = get(); next = accumulatorFunction.applyAsInt(prev, x); } while (!compareAndSet(prev, next)); return next; } public final int updateAndGet(IntUnaryOperator updateFunction) { int prev, next; do { prev = get(); next = updateFunction.applyAsInt(prev); } while (!compareAndSet(prev, next)); return next; }
They differ only in single line and obviously accumulateAndGet could be expressed easily via updateAndGet:
public final int accumulateAndGet(int x, IntBinaryOperator accumulatorFunction) { return updateAndGet(prev -> accumulatorFunction.applyAsInt(prev, x)); }
So updateAndGet is somewhat more basic operation and accumulateAndGet is a useful shortcut. Such shortcut might be especially helpful if your x is not effectively final:
int nextValue = 5; if(something) nextValue = 6; i.accumulateAndGet(nextValue, Math::max); // i.updateAndGet(prev -> Math.max(prev, nextValue)); -- will not work
i.incrementAndGet()andi.accumulateAndGet(1, Integer::sum)…accumulateAndGet()was added later, plus it can't useUnsafe.addAndGet(1)might be a better example, but even that wasn't usingUnsafeat the time it was created. I do, however, accept your general point; this question is just to clarify whether that was indeed the motivation.