Exemplo n.º 1
0
  public void addExecuteTime(long nanoSpan) {
    executeSpanNanoTotalUpdater.addAndGet(this, nanoSpan);

    for (; ; ) {
      long current = executeSpanNanoMaxUpdater.get(this);
      if (current < nanoSpan) {
        if (executeSpanNanoMaxUpdater.compareAndSet(this, current, nanoSpan)) {
          // 可能不准确,但是绝大多数情况下都会正确,性能换取一致性
          executeNanoSpanMaxOccurTime = System.currentTimeMillis();

          break;
        } else {
          continue;
        }
      } else {
        break;
      }
    }

    histogramRecord(nanoSpan);
  }