in geronimo-metrics-common/src/main/java/org/apache/geronimo/microprofile/metrics/common/HistogramImpl.java [131:154]
public void add(final long value) {
ensureUpToDate();
final Lock lock = this.lock.readLock();
lock.lock();
try {
final Value sample = new Value(value, Math.exp(ALPHA * (nowSec() - startTime)));
final double priority = sample.weight / Math.random();
final long size = count.incrementAndGet();
if (size <= BUCKET_SIZE) {
bucket.put(priority, sample);
} else { // iterate through the bucket until we need removing low priority entries to get a new space
double first = bucket.firstKey();
if (first < priority && bucket.putIfAbsent(priority, sample) == null) {
while (bucket.remove(first) == null) {
first = bucket.firstKey();
}
}
}
} finally {
lock.unlock();
}
}