public static void updateMax(AtomicLong max, long value) {
    while (true) {
      long cur = max.get();
      if (value <= cur) {
        break;
      }

      if (max.compareAndSet(cur, value)) {
        break;
      }
    }
  }
Updates a AtomicLong which is supposed to maintain the maximum values. This method is not
synchronized but is thread-safe.
hbase-common/src/main/java/org/apache/hadoop/hbase/util/AtomicUtils.java