Search in sources :

Example 1 with DoubleAdder

use of java.util.concurrent.atomic.DoubleAdder in project fastjson by alibaba.

the class DoubleAdderTest method test_long_add.

public void test_long_add() throws Exception {
    DoubleAdder adder = new DoubleAdder();
    adder.add(3);
    String json = JSON.toJSONString(adder);
    assertEquals("{\"value\":3.0}", json);
}
Also used : DoubleAdder(java.util.concurrent.atomic.DoubleAdder)

Example 2 with DoubleAdder

use of java.util.concurrent.atomic.DoubleAdder in project spring-boot by spring-projects.

the class BufferGaugeServiceSpeedTests method raw.

@Theory
public void raw(String input) throws Exception {
    iterate("writeRaw");
    double rate = number / watch.getLastTaskTimeMillis() * 1000;
    System.err.println("Rate(" + count + ")=" + rate + ", " + watch);
    watch.start("readRaw" + count);
    for (String name : names) {
        this.gauges.forEach(Pattern.compile(name).asPredicate(), new BiConsumer<String, GaugeBuffer>() {

            @Override
            public void accept(String name, GaugeBuffer value) {
                err.println(name + "=" + value);
            }
        });
    }
    final DoubleAdder total = new DoubleAdder();
    this.gauges.forEach(Pattern.compile(".*").asPredicate(), new BiConsumer<String, GaugeBuffer>() {

        @Override
        public void accept(String name, GaugeBuffer value) {
            total.add(value.getValue());
        }
    });
    watch.stop();
    System.err.println("Read(" + count + ")=" + watch.getLastTaskTimeMillis() + "ms");
    assertThat(number * threadCount < total.longValue()).isTrue();
}
Also used : DoubleAdder(java.util.concurrent.atomic.DoubleAdder) Theory(org.junit.experimental.theories.Theory)

Example 3 with DoubleAdder

use of java.util.concurrent.atomic.DoubleAdder in project jdk8u_jdk by JetBrains.

the class Serial method testDoubleAdder.

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");
}
Also used : DoubleAdder(java.util.concurrent.atomic.DoubleAdder)

Example 4 with DoubleAdder

use of java.util.concurrent.atomic.DoubleAdder in project jdk8u_jdk by JetBrains.

the class DoubleAdderDemo method adderTest.

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());
}
Also used : DoubleAdder(java.util.concurrent.atomic.DoubleAdder) Phaser(java.util.concurrent.Phaser)

Aggregations

DoubleAdder (java.util.concurrent.atomic.DoubleAdder)4 Phaser (java.util.concurrent.Phaser)1 Theory (org.junit.experimental.theories.Theory)1