public void refresh() { long count = 0; sum = sumCounter.sumThenReset(); for (int i = 0; i < buckets.length; i++) { long value = buckets[i].sumThenReset(); count += value; values[i] = value; } this.count = count; }
/** * Number of checksum verification failures. It also * clears the counter. */ public static final long getAndResetChecksumFailuresCount() { return CHECKSUM_FAILURES.sumThenReset(); }
public void calculateRate(double period) { checkArgument(period > 0, "Invalid period %s to calculate rate", period); count = countAdder.sumThenReset(); long sum = valueAdder.sumThenReset(); averageValue = count != 0 ? sum / count : 0.0d; rate = count / period; valueRate = sum / period; }
/** * Mark the passage of time and decay the current rate accordingly. */ void tick() { final long count = uncounted.sumThenReset(); final double instantRate = count / interval; if (initialized) { rate += (alpha * (instantRate - rate)); } else { rate = instantRate; initialized = true; } }
/** * Mark the passage of time and decay the current rate accordingly. */ public void tick() { final long count = uncounted.sumThenReset(); final double instantRate = count / interval; if (initialized) { final double oldRate = this.rate; rate = oldRate + (alpha * (instantRate - oldRate)); } else { rate = instantRate; initialized = true; } }
/** * Mark the passage of time and decay the current rate accordingly. */ void tick() { final long count = uncounted.sumThenReset(); final double instantRate = count / interval; if (initialized) { double currentRate = rate; currentRate += (alpha * (instantRate - currentRate)); // we may lose changes that happen at the very same moment as the previous two lines, though better than being // inconsistent rate = currentRate; } else { rate = instantRate; initialized = true; } }
private void writeNumDroppedConnectionsLog() { loggingScheduled.set(false); final long dropped = numDroppedConnections.sumThenReset(); if (dropped > 0) { logger.warn("Dropped {} connection(s) to limit the number of open connections to {}", dropped, maxNumConnections); } }
public long getTotalAppCounter(boolean reset) { LongAdder longAdder = specificCounters[APP_STAT_COUNTER_INDEX]; return reset ? longAdder.sumThenReset() : longAdder.sum(); }
public long getTotalMqttCounter(boolean reset) { LongAdder longAdder = specificCounters[MQTT_STAT_COUNTER_INDEX]; return reset ? longAdder.sumThenReset() : longAdder.sum(); }
@SuppressWarnings("BusyWait") @Override public void run() { while (true) { try { Thread.sleep(10000); } catch (InterruptedException ignored) { break; } info(">>> Adds/sec: " + cnt.sumThenReset() / 10); } } });
@SuppressWarnings("BusyWait") @Override public void run() { while (!done) { try { Thread.sleep(5000); } catch (InterruptedException ignored) { return; } System.out.println(new Date() + " Notifications per sec: " + (cnt.sumThenReset() / 5)); } } };
@Override public Object call() throws Exception { while (!finished.get()) { U.sleep(5000); info("Ops/sec: " + cnt.sumThenReset() / 5); } return null; } }, 1);
@Override public Object call() throws Exception { while (!finished.get()) { U.sleep(5000); info("Ops/sec: " + cnt.sumThenReset() / 5); } return null; } }, 1);
@Override public Object call() throws Exception { while (!finished.get()) { U.sleep(5000); info("Ops/sec: " + cnt.sumThenReset() / 5); } return null; } }, 1);
@Override public Object call() throws Exception { while (!finished.get()) { U.sleep(5000); info("Ops/sec: " + cnt.sumThenReset() / 5); } return null; } }, 1);
@Override public Object call() throws Exception { for (;;) { U.sleep(1000); info("Ops/sec: " + cnt.sumThenReset()); } } }, 1);
@SuppressWarnings({"BusyWait"}) @Override public void run() { GridCumulativeAverage avgTasksPerSec = new GridCumulativeAverage(); try { while (!finish.get()) { Thread.sleep(UPDATE_INTERVAL_SEC * 1000); long curTasksPerSec = execCnt.sumThenReset() / UPDATE_INTERVAL_SEC; X.println(">>> Tasks/s: " + curTasksPerSec); avgTasksPerSec.update(curTasksPerSec); } } catch (InterruptedException ignored) { X.println(">>> Interrupted."); Thread.currentThread().interrupt(); } } });
/** * KeySetView.spliterator returns spliterator over the elements in this set */ public void testKeySetSpliterator() { LongAdder adder = new LongAdder(); ConcurrentMap map = map5(); Set set = map.keySet(); Spliterator<Integer> sp = set.spliterator(); checkSpliteratorCharacteristics(sp, CONCURRENT | DISTINCT | NONNULL); assertEquals(sp.estimateSize(), map.size()); Spliterator<Integer> sp2 = sp.trySplit(); sp.forEachRemaining((Integer x) -> adder.add(x.longValue())); long v = adder.sumThenReset(); sp2.forEachRemaining((Integer x) -> adder.add(x.longValue())); long v2 = adder.sum(); assertEquals(v + v2, 15); }
Thread.sleep(UPDATE_INTERVAL_SEC * 1000); long txPerSec = txCnt.sumThenReset() / UPDATE_INTERVAL_SEC;
Thread.sleep(UPDATE_INTERVAL_SEC * 1000); long txPerSec = txCnt.sumThenReset() / UPDATE_INTERVAL_SEC;