public void update(long value,long timestamp){
  rescaleIfNeeded();
  lockForRegularUsage();
  try {
    final double priority=weight(timestamp - startTime) / random.nextDouble();
    final long newCount=count.incrementAndGet();
    if (newCount <= reservoirSize) {
      values.put(priority,value);
    }
 else {
      Double first=values.firstKey();
      if (first < priority) {
        if (values.putIfAbsent(priority,value) == null) {
          while (values.remove(first) == null) {
            first=values.firstKey();
          }
        }
      }
    }
  }
  finally {
    unlockForRegularUsage();
  }
}

public void update ( long value , long timestamp ) { rescaleIfNeeded ( ) ; lockForRegularUsage ( ) ; try { final double priority = weight ( timestamp - startTime ) / random . nextDouble ( ) ; final long newCount = count . incrementAndGet ( ) ; if ( newCount <= reservoirSize ) { values . put ( priority , value ) ; } else { Double first = values . firstKey ( ) ; if ( first < priority ) { if ( values . putIfAbsent ( priority , value ) == null ) { while ( values . remove ( first ) == null ) { first = values . firstKey ( ) ; } } } } } finally { unlockForRegularUsage ( ) ; } }
adds an old value with a fixed timestamp to the sample .
