public void recordMax(long currentValue) {
    boolean done = false;
    while (!done) {
      long maxValue = max.get();
      if (currentValue <= maxValue) {
        done = true;
      } else {
        done = max.compareAndSet(maxValue, currentValue);
        if (done) {
          stats.incLong(statId, currentValue - maxValue);
        }
      }
    }
  }
This class holds the max value of a stat inside an AtomicLong. Every time a higher value is found
the class will forward the delta between the old max and the new max to the statistics class.
This pattern is a lock-less alternative to calling Statistics.getLong and then updating the max.
geode-core/src/main/java/org/apache/geode/distributed/internal/MaxLongGauge.java