Search in sources :

Example 1 with DoubleAdder

use of java8.util.concurrent.atomic.DoubleAdder in project streamsupport by stefan-zobel.

the class DoubleAdderTest method testSumThenReset.

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

Example 2 with DoubleAdder

use of java8.util.concurrent.atomic.DoubleAdder in project streamsupport by stefan-zobel.

the class DoubleAdderTest method testIntValue.

/**
 * intValue returns current value.
 */
public void testIntValue() {
    DoubleAdder ai = new DoubleAdder();
    assertEquals(0, ai.intValue());
    ai.add(1.0);
    assertEquals(1, ai.intValue());
}
Also used : DoubleAdder(java8.util.concurrent.atomic.DoubleAdder)

Example 3 with DoubleAdder

use of java8.util.concurrent.atomic.DoubleAdder in project streamsupport by stefan-zobel.

the class DoubleAdderTest method testDoubleValue.

/**
 * doubleValue returns current value.
 */
public void testDoubleValue() {
    DoubleAdder ai = new DoubleAdder();
    assertEquals(0.0, ai.doubleValue());
    ai.add(1.0);
    assertEquals(1.0, ai.doubleValue());
}
Also used : DoubleAdder(java8.util.concurrent.atomic.DoubleAdder)

Example 4 with DoubleAdder

use of java8.util.concurrent.atomic.DoubleAdder in project streamsupport by stefan-zobel.

the class DoubleAdderTest method testConstructor.

/**
 * default constructed initializes to zero
 */
public void testConstructor() {
    DoubleAdder ai = new DoubleAdder();
    assertEquals(0.0, ai.sum());
}
Also used : DoubleAdder(java8.util.concurrent.atomic.DoubleAdder)

Example 5 with DoubleAdder

use of java8.util.concurrent.atomic.DoubleAdder in project streamsupport by stefan-zobel.

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(java8.util.concurrent.atomic.DoubleAdder) Phaser(java8.util.concurrent.Phaser)

Aggregations

DoubleAdder (java8.util.concurrent.atomic.DoubleAdder)12 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 ExecutorService (java.util.concurrent.ExecutorService)1 Phaser (java8.util.concurrent.Phaser)1