类java.util.concurrent.atomic.DoubleAccumulator源码实例Demo

下面列出了怎么用java.util.concurrent.atomic.DoubleAccumulator的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: openjdk-jdk9   文件: DoubleAccumulatorTest.java
/**
 * 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();
}
 
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);
}
 
源代码3 项目: skywalking   文件: SkywalkingTimer.java
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);
}
 
源代码4 项目: j2objc   文件: DoubleAccumulatorTest.java
/**
 * 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();
}
 
源代码5 项目: dragonwell8_jdk   文件: Serial.java
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");
}
 
源代码6 项目: TencentKona-8   文件: Serial.java
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");
}
 
源代码7 项目: native-obfuscator   文件: Serial.java
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");
}
 
源代码8 项目: jdk8u60   文件: Serial.java
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");
}
 
源代码9 项目: openjdk-jdk8u   文件: Serial.java
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");
}
 
源代码10 项目: openjdk-jdk8u-backup   文件: Serial.java
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");
}
 
源代码11 项目: openjdk-jdk9   文件: Serial.java
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");
}
 
源代码12 项目: openjdk-jdk9   文件: DoubleAccumulatorTest.java
/**
 * 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());
}
 
源代码13 项目: openjdk-jdk9   文件: DoubleAccumulatorTest.java
/**
 * 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());
}
 
源代码14 项目: openjdk-jdk9   文件: DoubleAccumulatorTest.java
/**
 * 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());
}
 
源代码15 项目: openjdk-jdk9   文件: DoubleAccumulatorTest.java
/**
 * 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());
}
 
源代码16 项目: openjdk-jdk9   文件: DoubleAccumulatorTest.java
/**
 * 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());
}
 
源代码17 项目: openjdk-jdk9   文件: DoubleAccumulatorTest.java
/**
 * 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());
}
 
源代码18 项目: openjdk-jdk9   文件: DoubleAccumulatorTest.java
/**
 * 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());
}
 
源代码19 项目: openjdk-jdk9   文件: DoubleAccumulatorTest.java
/**
 * 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());
}
 
源代码20 项目: openjdk-jdk9   文件: DoubleAccumulatorTest.java
public void run() {
    phaser.arriveAndAwaitAdvance();
    DoubleAccumulator a = acc;
    for (int i = 0; i < incs; ++i)
        a.accumulate(i);
    result = a.get();
    phaser.arrive();
}
 
源代码21 项目: jdk8u-jdk   文件: Serial.java
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");
}
 
源代码22 项目: hottub   文件: Serial.java
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");
}
 
源代码23 项目: openjdk-8-source   文件: Serial.java
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");
}
 
源代码24 项目: openjdk-8   文件: Serial.java
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");
}
 
源代码25 项目: jdk8u_jdk   文件: Serial.java
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");
}
 
源代码26 项目: jdk8u-jdk   文件: Serial.java
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");
}
 
源代码27 项目: jdk8u-dev-jdk   文件: Serial.java
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");
}
 
源代码28 项目: j2objc   文件: DoubleAccumulatorTest.java
/**
 * 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());
}
 
源代码29 项目: j2objc   文件: DoubleAccumulatorTest.java
/**
 * 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());
}
 
源代码30 项目: j2objc   文件: DoubleAccumulatorTest.java
/**
 * 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());
}