java.util.concurrent.atomic.DoubleAccumulator Java Examples

The following examples show how to use java.util.concurrent.atomic.DoubleAccumulator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DoubleAccumulatorTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * accumulates by multiple threads produce correct result
 */
public void testAccumulateAndGetMT() {
    final int incs = 1000000;
    final int nthreads = 4;
    final ExecutorService pool = Executors.newCachedThreadPool();
    DoubleAccumulator a = new DoubleAccumulator(Double::max, 0.0);
    Phaser phaser = new Phaser(nthreads + 1);
    for (int i = 0; i < nthreads; ++i)
        pool.execute(new AccTask(a, phaser, incs));
    phaser.arriveAndAwaitAdvance();
    phaser.arriveAndAwaitAdvance();
    double expected = incs - 1;
    double result = a.get();
    assertEquals(expected, result);
    pool.shutdown();
}
 
Example #2
Source File: DoubleAccumulatorTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * accumulates by multiple threads produce correct result
 */
public void testAccumulateAndGetMT() {
    final int incs = 1000000;
    final int nthreads = 4;
    final ExecutorService pool = Executors.newCachedThreadPool();
    DoubleAccumulator a = new DoubleAccumulator(Double::max, 0.0);
    Phaser phaser = new Phaser(nthreads + 1);
    for (int i = 0; i < nthreads; ++i)
        pool.execute(new AccTask(a, phaser, incs));
    phaser.arriveAndAwaitAdvance();
    phaser.arriveAndAwaitAdvance();
    double expected = incs - 1;
    double result = a.get();
    assertEquals(expected, result);
    pool.shutdown();
}
 
Example #3
Source File: SkywalkingDistributionSummary.java    From skywalking with Apache License 2.0 6 votes vote down vote up
protected SkywalkingDistributionSummary(Id id, MeterId meterId, SkywalkingConfig config, Clock clock,
                                        DistributionStatisticConfig distributionStatisticConfig, double scale,
                                        boolean supportsAggregablePercentiles) {
    super(id, clock, distributionStatisticConfig, scale, supportsAggregablePercentiles);

    // meter base name
    String baseName = meterId.getName();

    this.counter = MeterBuilder.buildCounter(meterId.copyTo(baseName + "_count", MeterId.MeterType.COUNTER), config);
    this.sum = MeterBuilder.buildCounter(meterId.copyTo(baseName + "_sum", MeterId.MeterType.COUNTER), config);
    this.maxAdder = new DoubleAccumulator((a, b) -> a > b ? a : b, 0.000);
    this.max = MeterFactory.gauge(meterId.copyTo(baseName + "_max", MeterId.MeterType.GAUGE),
        () -> maxAdder.doubleValue()).build();

    this.histogram = MeterBuilder.buildHistogram(meterId, supportsAggregablePercentiles, distributionStatisticConfig, false);
}
 
Example #4
Source File: SkywalkingTimer.java    From skywalking with Apache License 2.0 6 votes vote down vote up
protected SkywalkingTimer(Id id, MeterId meterId, SkywalkingConfig config, Clock clock,
                          DistributionStatisticConfig distributionStatisticConfig, PauseDetector pauseDetector,
                          TimeUnit baseTimeUnit, boolean supportsAggregablePercentiles) {
    super(id, clock, distributionStatisticConfig, pauseDetector, baseTimeUnit, supportsAggregablePercentiles);

    // meter base name
    String baseName = meterId.getName();

    this.counter = MeterBuilder.buildCounter(meterId.copyTo(baseName + "_count", MeterId.MeterType.COUNTER), config);
    this.sum = MeterBuilder.buildCounter(meterId.copyTo(baseName + "_sum", MeterId.MeterType.COUNTER), config);
    this.maxAdder = new DoubleAccumulator((a, b) -> a > b ? a : b, 0.000);
    this.max = MeterFactory.gauge(meterId.copyTo(baseName + "_max", MeterId.MeterType.GAUGE),
        () -> maxAdder.doubleValue()).build();

    this.histogram = MeterBuilder.buildHistogram(meterId, supportsAggregablePercentiles, distributionStatisticConfig, true);
}
 
Example #5
Source File: DoubleAccumulatorTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * accumulate accumulates given value to current, and get returns current value
 */
public void testAccumulateAndGet() {
    DoubleAccumulator ai = new DoubleAccumulator(Double::max, 0.0);
    ai.accumulate(2.0);
    assertEquals(2.0, ai.get());
    ai.accumulate(-4.0);
    assertEquals(2.0, ai.get());
    ai.accumulate(4.0);
    assertEquals(4.0, ai.get());
}
 
Example #6
Source File: Serial.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
static void testDoubleAccumulator() {
    DoubleBinaryOperator plus = (DoubleBinaryOperator & Serializable) (x, y) -> x + y;
    DoubleAccumulator a = new DoubleAccumulator(plus, 13.9d);
    a.accumulate(17.5d);
    DoubleAccumulator result = echo(a);
    if (result.get() != a.get())
        throw new RuntimeException("Unexpected value");
    a.reset();
    result.reset();
    if (result.get() != a.get())
        throw new RuntimeException("Unexpected value after reset");

    checkSerialClassName(a, "java.util.concurrent.atomic.DoubleAccumulator$SerializationProxy");
}
 
Example #7
Source File: Serial.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
static void testDoubleAccumulator() {
    DoubleBinaryOperator plus = (DoubleBinaryOperator & Serializable) (x, y) -> x + y;
    DoubleAccumulator a = new DoubleAccumulator(plus, 13.9d);
    a.accumulate(17.5d);
    DoubleAccumulator result = echo(a);
    if (result.get() != a.get())
        throw new RuntimeException("Unexpected value");
    a.reset();
    result.reset();
    if (result.get() != a.get())
        throw new RuntimeException("Unexpected value after reset");

    checkSerialClassName(a, "java.util.concurrent.atomic.DoubleAccumulator$SerializationProxy");
}
 
Example #8
Source File: Serial.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
static void testDoubleAccumulator() {
    DoubleBinaryOperator plus = (DoubleBinaryOperator & Serializable) (x, y) -> x + y;
    DoubleAccumulator a = new DoubleAccumulator(plus, 13.9d);
    a.accumulate(17.5d);
    DoubleAccumulator result = echo(a);
    if (result.get() != a.get())
        throw new RuntimeException("Unexpected value");
    a.reset();
    result.reset();
    if (result.get() != a.get())
        throw new RuntimeException("Unexpected value after reset");

    checkSerialClassName(a, "java.util.concurrent.atomic.DoubleAccumulator$SerializationProxy");
}
 
Example #9
Source File: Serial.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
static void testDoubleAccumulator() {
    DoubleBinaryOperator plus = (DoubleBinaryOperator & Serializable) (x, y) -> x + y;
    DoubleAccumulator a = new DoubleAccumulator(plus, 13.9d);
    a.accumulate(17.5d);
    DoubleAccumulator result = echo(a);
    if (result.get() != a.get())
        throw new RuntimeException("Unexpected value");
    a.reset();
    result.reset();
    if (result.get() != a.get())
        throw new RuntimeException("Unexpected value after reset");

    checkSerialClassName(a, "java.util.concurrent.atomic.DoubleAccumulator$SerializationProxy");
}
 
Example #10
Source File: Serial.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
static void testDoubleAccumulator() {
    DoubleBinaryOperator plus = (DoubleBinaryOperator & Serializable) (x, y) -> x + y;
    DoubleAccumulator a = new DoubleAccumulator(plus, 13.9d);
    a.accumulate(17.5d);
    DoubleAccumulator result = echo(a);
    if (result.get() != a.get())
        throw new RuntimeException("Unexpected value");
    a.reset();
    result.reset();
    if (result.get() != a.get())
        throw new RuntimeException("Unexpected value after reset");

    checkSerialClassName(a, "java.util.concurrent.atomic.DoubleAccumulator$SerializationProxy");
}
 
Example #11
Source File: Serial.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
static void testDoubleAccumulator() {
    DoubleBinaryOperator plus = (DoubleBinaryOperator & Serializable) (x, y) -> x + y;
    DoubleAccumulator a = new DoubleAccumulator(plus, 13.9d);
    a.accumulate(17.5d);
    DoubleAccumulator result = echo(a);
    if (result.get() != a.get())
        throw new RuntimeException("Unexpected value");
    a.reset();
    result.reset();
    if (result.get() != a.get())
        throw new RuntimeException("Unexpected value after reset");

    checkSerialClassName(a, "java.util.concurrent.atomic.DoubleAccumulator$SerializationProxy");
}
 
Example #12
Source File: Serial.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
static void testDoubleAccumulator() {
    DoubleBinaryOperator plus = (DoubleBinaryOperator & Serializable) (x, y) -> x + y;
    DoubleAccumulator a = new DoubleAccumulator(plus, 13.9d);
    a.accumulate(17.5d);
    DoubleAccumulator result = echo(a);
    if (result.get() != a.get())
        throw new RuntimeException("Unexpected value");
    a.reset();
    result.reset();
    if (result.get() != a.get())
        throw new RuntimeException("Unexpected value after reset");

    checkSerialClassName(a, "java.util.concurrent.atomic.DoubleAccumulator$SerializationProxy");
}
 
Example #13
Source File: DoubleAccumulatorTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * reset() causes subsequent get() to return zero
 */
public void testReset() {
    DoubleAccumulator ai = new DoubleAccumulator(Double::max, 0.0);
    ai.accumulate(2.0);
    assertEquals(2.0, ai.get());
    ai.reset();
    assertEquals(0.0, ai.get());
}
 
Example #14
Source File: DoubleAccumulatorTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * getThenReset() returns current value; subsequent get() returns zero
 */
public void testGetThenReset() {
    DoubleAccumulator ai = new DoubleAccumulator(Double::max, 0.0);
    ai.accumulate(2.0);
    assertEquals(2.0, ai.get());
    assertEquals(2.0, ai.getThenReset());
    assertEquals(0.0, ai.get());
}
 
Example #15
Source File: DoubleAccumulatorTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * toString returns current value.
 */
public void testToString() {
    DoubleAccumulator ai = new DoubleAccumulator(Double::max, 0.0);
    assertEquals("0.0", ai.toString());
    ai.accumulate(1.0);
    assertEquals(Double.toString(1.0), ai.toString());
}
 
Example #16
Source File: DoubleAccumulatorTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * intValue returns current value.
 */
public void testIntValue() {
    DoubleAccumulator ai = new DoubleAccumulator(Double::max, 0.0);
    assertEquals(0, ai.intValue());
    ai.accumulate(1.0);
    assertEquals(1, ai.intValue());
}
 
Example #17
Source File: DoubleAccumulatorTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * longValue returns current value.
 */
public void testLongValue() {
    DoubleAccumulator ai = new DoubleAccumulator(Double::max, 0.0);
    assertEquals(0, ai.longValue());
    ai.accumulate(1.0);
    assertEquals(1, ai.longValue());
}
 
Example #18
Source File: DoubleAccumulatorTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * floatValue returns current value.
 */
public void testFloatValue() {
    DoubleAccumulator ai = new DoubleAccumulator(Double::max, 0.0);
    assertEquals(0.0f, ai.floatValue());
    ai.accumulate(1.0);
    assertEquals(1.0f, ai.floatValue());
}
 
Example #19
Source File: DoubleAccumulatorTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * doubleValue returns current value.
 */
public void testDoubleValue() {
    DoubleAccumulator ai = new DoubleAccumulator(Double::max, 0.0);
    assertEquals(0.0, ai.doubleValue());
    ai.accumulate(1.0);
    assertEquals(1.0, ai.doubleValue());
}
 
Example #20
Source File: DoubleAccumulatorTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void run() {
    phaser.arriveAndAwaitAdvance();
    DoubleAccumulator a = acc;
    for (int i = 0; i < incs; ++i)
        a.accumulate(i);
    result = a.get();
    phaser.arrive();
}
 
Example #21
Source File: DoubleAccumulatorTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * getThenReset() returns current value; subsequent get() returns zero
 */
public void testGetThenReset() {
    DoubleAccumulator ai = new DoubleAccumulator(Double::max, 0.0);
    ai.accumulate(2.0);
    assertEquals(2.0, ai.get());
    assertEquals(2.0, ai.getThenReset());
    assertEquals(0.0, ai.get());
}
 
Example #22
Source File: Serial.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
static void testDoubleAccumulator() {
    DoubleBinaryOperator plus = (DoubleBinaryOperator & Serializable) (x, y) -> x + y;
    DoubleAccumulator a = new DoubleAccumulator(plus, 13.9d);
    a.accumulate(17.5d);
    DoubleAccumulator result = echo(a);
    if (result.get() != a.get())
        throw new RuntimeException("Unexpected value");
    a.reset();
    result.reset();
    if (result.get() != a.get())
        throw new RuntimeException("Unexpected value after reset");

    checkSerialClassName(a, "java.util.concurrent.atomic.DoubleAccumulator$SerializationProxy");
}
 
Example #23
Source File: Serial.java    From native-obfuscator with GNU General Public License v3.0 5 votes vote down vote up
static void testDoubleAccumulator() {
    DoubleBinaryOperator plus = (DoubleBinaryOperator & Serializable) (x, y) -> x + y;
    DoubleAccumulator a = new DoubleAccumulator(plus, 13.9d);
    a.accumulate(17.5d);
    DoubleAccumulator result = echo(a);
    if (result.get() != a.get())
        throw new RuntimeException("Unexpected value");
    a.reset();
    result.reset();
    if (result.get() != a.get())
        throw new RuntimeException("Unexpected value after reset");

    checkSerialClassName(a, "java.util.concurrent.atomic.DoubleAccumulator$SerializationProxy");
}
 
Example #24
Source File: Serial.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
static void testDoubleAccumulator() {
    DoubleBinaryOperator plus = (DoubleBinaryOperator & Serializable) (x, y) -> x + y;
    DoubleAccumulator a = new DoubleAccumulator(plus, 13.9d);
    a.accumulate(17.5d);
    DoubleAccumulator result = echo(a);
    if (result.get() != a.get())
        throw new RuntimeException("Unexpected value");
    a.reset();
    result.reset();
    if (result.get() != a.get())
        throw new RuntimeException("Unexpected value after reset");

    checkSerialClassName(a, "java.util.concurrent.atomic.DoubleAccumulator$SerializationProxy");
}
 
Example #25
Source File: Serial.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
static void testDoubleAccumulator() {
    DoubleBinaryOperator plus = (DoubleBinaryOperator & Serializable) (x, y) -> x + y;
    DoubleAccumulator a = new DoubleAccumulator(plus, 13.9d);
    a.accumulate(17.5d);
    DoubleAccumulator result = echo(a);
    if (result.get() != a.get())
        throw new RuntimeException("Unexpected value");
    a.reset();
    result.reset();
    if (result.get() != a.get())
        throw new RuntimeException("Unexpected value after reset");

    checkSerialClassName(a, "java.util.concurrent.atomic.DoubleAccumulator$SerializationProxy");
}
 
Example #26
Source File: Serial.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
static void testDoubleAccumulator() {
    DoubleBinaryOperator plus = (DoubleBinaryOperator & Serializable) (x, y) -> x + y;
    DoubleAccumulator a = new DoubleAccumulator(plus, 13.9d);
    a.accumulate(17.5d);
    DoubleAccumulator result = echo(a);
    if (result.get() != a.get())
        throw new RuntimeException("Unexpected value");
    a.reset();
    result.reset();
    if (result.get() != a.get())
        throw new RuntimeException("Unexpected value after reset");

    checkSerialClassName(a, "java.util.concurrent.atomic.DoubleAccumulator$SerializationProxy");
}
 
Example #27
Source File: Serial.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
static void testDoubleAccumulator() {
    DoubleBinaryOperator plus = (DoubleBinaryOperator & Serializable) (x, y) -> x + y;
    DoubleAccumulator a = new DoubleAccumulator(plus, 13.9d);
    a.accumulate(17.5d);
    DoubleAccumulator result = echo(a);
    if (result.get() != a.get())
        throw new RuntimeException("Unexpected value");
    a.reset();
    result.reset();
    if (result.get() != a.get())
        throw new RuntimeException("Unexpected value after reset");

    checkSerialClassName(a, "java.util.concurrent.atomic.DoubleAccumulator$SerializationProxy");
}
 
Example #28
Source File: DoubleAccumulatorTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * accumulate accumulates given value to current, and get returns current value
 */
public void testAccumulateAndGet() {
    DoubleAccumulator ai = new DoubleAccumulator(Double::max, 0.0);
    ai.accumulate(2.0);
    assertEquals(2.0, ai.get());
    ai.accumulate(-4.0);
    assertEquals(2.0, ai.get());
    ai.accumulate(4.0);
    assertEquals(4.0, ai.get());
}
 
Example #29
Source File: DoubleAccumulatorTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * reset() causes subsequent get() to return zero
 */
public void testReset() {
    DoubleAccumulator ai = new DoubleAccumulator(Double::max, 0.0);
    ai.accumulate(2.0);
    assertEquals(2.0, ai.get());
    ai.reset();
    assertEquals(0.0, ai.get());
}
 
Example #30
Source File: Serial.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
static void testDoubleAccumulator() {
    DoubleBinaryOperator plus = (DoubleBinaryOperator & Serializable) (x, y) -> x + y;
    DoubleAccumulator a = new DoubleAccumulator(plus, 13.9d);
    a.accumulate(17.5d);
    DoubleAccumulator result = echo(a);
    if (result.get() != a.get())
        throw new RuntimeException("Unexpected value");
    a.reset();
    result.reset();
    if (result.get() != a.get())
        throw new RuntimeException("Unexpected value after reset");

    checkSerialClassName(a, "java.util.concurrent.atomic.DoubleAccumulator$SerializationProxy");
}