public final V accumulateAndGet(V x,BinaryOperator<V> accumulatorFunction){
  V prev, next;
  do {
    prev=get();
    next=accumulatorFunction.apply(prev,x);
  }
 while (!compareAndSet(prev,next));
  return next;
}

public final V accumulateAndGet ( V x , BinaryOperator < V > accumulatorFunction ) { V prev , next ; do { prev = get ( ) ; next = accumulatorFunction . apply ( prev , x ) ; } while ( ! compareAndSet ( prev , next ) ) ; return next ; }
atomically updates the current value with the results of applying the given function to the current and given values , returning the updated value . the function should be side - effect - free , since it may be re - applied when attempted updates fail due to contention among threads . the function is applied with the current value as its first argument , and the given update as the second argument .
