当前位置: 首页>>代码示例>>Java>>正文


Java DoubleAdder类代码示例

本文整理汇总了Java中java.util.concurrent.atomic.DoubleAdder的典型用法代码示例。如果您正苦于以下问题:Java DoubleAdder类的具体用法?Java DoubleAdder怎么用?Java DoubleAdder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DoubleAdder类属于java.util.concurrent.atomic包,在下文中一共展示了DoubleAdder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: DoubleConsumer

import java.util.concurrent.atomic.DoubleAdder; //导入依赖的package包/类
@Test
public void DoubleConsumer()
{
    DoubleAdder adder = new DoubleAdder();
    // TODO - Convert the anonymous inner class to a lambda
    DoubleConsumer consumer = new DoubleConsumer()
    {
        @Override
        public void accept(double value)
        {
            adder.add(value);
        }
    };
    DoubleStream.of(1.0, 2.0, 3.0, 4.0, 5.0).forEach(consumer);
    Assert.assertEquals(15.0, adder.doubleValue(), 0.0);
}
 
开发者ID:BNYMellon,项目名称:CodeKatas,代码行数:17,代码来源:PrimitiveFunctionalInterfaceTest.java

示例2: testAddAndSumMT

import java.util.concurrent.atomic.DoubleAdder; //导入依赖的package包/类
/**
 * adds by multiple threads produce correct sum
 */
public void testAddAndSumMT() throws Throwable {
    final int incs = 1000000;
    final int nthreads = 4;
    final ExecutorService pool = Executors.newCachedThreadPool();
    DoubleAdder a = new DoubleAdder();
    CyclicBarrier barrier = new CyclicBarrier(nthreads + 1);
    for (int i = 0; i < nthreads; ++i)
        pool.execute(new AdderTask(a, barrier, incs));
    barrier.await();
    barrier.await();
    double total = (long)nthreads * incs;
    double sum = a.sum();
    assertEquals(sum, total);
    pool.shutdown();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:DoubleAdderTest.java

示例3: measure

import java.util.concurrent.atomic.DoubleAdder; //导入依赖的package包/类
@Override
public List<Measurement> measure() {
    ConcurrentMap<String, DoubleAdder> mapToProcess = counts;
    counts = new ConcurrentHashMap<>();

    if (cloudwatchClient != null && hasCloudwatchConfig != null && hasCloudwatchConfig.auditeventStatisticsEnabled()) {
        List<CloudwatchClient.CloudwatchStatistic> statistics = mapToProcess.entrySet().stream()
                .map(e -> new CloudwatchClient.CloudwatchStatistic(e.getKey(), e.getValue().doubleValue()))
                .collect(toList());
        cloudwatchClient.sendStatistics(hasCloudwatchConfig.auditeventStatisticsNamespace(), statistics);
    }

    return mapToProcess.entrySet().stream()
            .map(e -> new Measurement("audit." + e.getKey(), "INFO", "Last minute: " + e.getValue().doubleValue()))
            .collect(toList());
}
 
开发者ID:Espenhh,项目名称:panopticon,代码行数:17,代码来源:AbstractEventLogger.java

示例4: write

import java.util.concurrent.atomic.DoubleAdder; //导入依赖的package包/类
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
    SerializeWriter out = serializer.out;
    if (object instanceof LongAdder) {
        out.writeFieldValue('{', "value", ((LongAdder) object).longValue());
        out.write('}');
    } else  if (object instanceof DoubleAdder) {
        out.writeFieldValue('{', "value", ((DoubleAdder) object).doubleValue());
        out.write('}');
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:AdderSerializer.java

示例5: test_long_add

import java.util.concurrent.atomic.DoubleAdder; //导入依赖的package包/类
public void test_long_add() throws Exception {
    DoubleAdder adder = new DoubleAdder();
    adder.add(3);

    String json = JSON.toJSONString(adder);
    assertEquals("{\"value\":3.0}", json);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:8,代码来源:DoubleAdderTest.java

示例6: adderTest

import java.util.concurrent.atomic.DoubleAdder; //导入依赖的package包/类
static void adderTest(int nthreads, int incs) {
    System.out.print("DoubleAdder  ");
    Phaser phaser = new Phaser(nthreads + 1);
    DoubleAdder a = new DoubleAdder();
    for (int i = 0; i < nthreads; ++i)
        pool.execute(new AdderTask(a, phaser, incs));
    report(nthreads, incs, timeTasks(phaser), a.sum());
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:9,代码来源:DoubleAdderDemo.java

示例7: run

import java.util.concurrent.atomic.DoubleAdder; //导入依赖的package包/类
public void run() {
    phaser.arriveAndAwaitAdvance();
    phaser.arriveAndAwaitAdvance();
    DoubleAdder a = adder;
    for (int i = 0; i < incs; ++i)
        a.add(1.0);
    result = a.sum();
    phaser.arrive();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:10,代码来源:DoubleAdderDemo.java

示例8: testDoubleAdder

import java.util.concurrent.atomic.DoubleAdder; //导入依赖的package包/类
static void testDoubleAdder() {
    DoubleAdder a = new DoubleAdder();
    a.add(20.1d);
    DoubleAdder result = echo(a);
    if (result.doubleValue() != a.doubleValue())
        throw new RuntimeException("Unexpected doubleValue");

    checkSerialClassName(a, "java.util.concurrent.atomic.DoubleAdder$SerializationProxy");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:10,代码来源:Serial.java

示例9: testAddAndSum

import java.util.concurrent.atomic.DoubleAdder; //导入依赖的package包/类
/**
 * add adds given value to current, and sum returns current value
 */
public void testAddAndSum() {
    DoubleAdder ai = new DoubleAdder();
    ai.add(2.0);
    assertEquals(2.0, ai.sum());
    ai.add(-4.0);
    assertEquals(-2.0, ai.sum());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:DoubleAdderTest.java

示例10: testReset

import java.util.concurrent.atomic.DoubleAdder; //导入依赖的package包/类
/**
 * reset() causes subsequent sum() to return zero
 */
public void testReset() {
    DoubleAdder ai = new DoubleAdder();
    ai.add(2.0);
    assertEquals(2.0, ai.sum());
    ai.reset();
    assertEquals(0.0, ai.sum());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:DoubleAdderTest.java

示例11: testSumThenReset

import java.util.concurrent.atomic.DoubleAdder; //导入依赖的package包/类
/**
 * sumThenReset() returns sum; subsequent sum() returns zero
 */
public void testSumThenReset() {
    DoubleAdder ai = new DoubleAdder();
    ai.add(2.0);
    assertEquals(2.0, ai.sum());
    assertEquals(2.0, ai.sumThenReset());
    assertEquals(0.0, ai.sum());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:DoubleAdderTest.java

示例12: testSerialization

import java.util.concurrent.atomic.DoubleAdder; //导入依赖的package包/类
/**
 * a deserialized/reserialized adder holds same value
 */
public void testSerialization() throws Exception {
    DoubleAdder x = new DoubleAdder();
    DoubleAdder y = serialClone(x);
    assertNotSame(x, y);
    x.add(-22.0);
    DoubleAdder z = serialClone(x);
    assertEquals(-22.0, x.sum());
    assertEquals(0.0, y.sum());
    assertEquals(-22.0, z.sum());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:DoubleAdderTest.java

示例13: testToString

import java.util.concurrent.atomic.DoubleAdder; //导入依赖的package包/类
/**
 * toString returns current value.
 */
public void testToString() {
    DoubleAdder ai = new DoubleAdder();
    assertEquals(Double.toString(0.0), ai.toString());
    ai.add(1.0);
    assertEquals(Double.toString(1.0), ai.toString());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:DoubleAdderTest.java

示例14: testIntValue

import java.util.concurrent.atomic.DoubleAdder; //导入依赖的package包/类
/**
 * intValue returns current value.
 */
public void testIntValue() {
    DoubleAdder ai = new DoubleAdder();
    assertEquals(0, ai.intValue());
    ai.add(1.0);
    assertEquals(1, ai.intValue());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:DoubleAdderTest.java

示例15: testLongValue

import java.util.concurrent.atomic.DoubleAdder; //导入依赖的package包/类
/**
 * longValue returns current value.
 */
public void testLongValue() {
    DoubleAdder ai = new DoubleAdder();
    assertEquals(0, ai.longValue());
    ai.add(1.0);
    assertEquals(1, ai.longValue());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:DoubleAdderTest.java


注:本文中的java.util.concurrent.atomic.DoubleAdder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。