Search in sources :

Example 36 with LongAdder

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

the class LongAdderTest method testIncrementAndSum.

/**
 * incrementAndGet increments and returns current value
 */
public void testIncrementAndSum() {
    LongAdder ai = new LongAdder();
    ai.increment();
    assertEquals(1, ai.sum());
    ai.increment();
    assertEquals(2, ai.sum());
}
Also used : LongAdder(java8.util.concurrent.atomic.LongAdder)

Example 37 with LongAdder

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

the class LongAdderTest method testLongValue.

/**
 * longValue returns current value.
 */
public void testLongValue() {
    LongAdder ai = new LongAdder();
    assertEquals(0, ai.longValue());
    ai.increment();
    assertEquals(1, ai.longValue());
}
Also used : LongAdder(java8.util.concurrent.atomic.LongAdder)

Example 38 with LongAdder

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

the class LongAdderTest method testDoubleValue.

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

Example 39 with LongAdder

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

the class SplittableRandomTest method testUnsizedDoublesCount.

/**
 * A parallel unsized stream of doubles generates at least 100 values
 */
public void testUnsizedDoublesCount() {
    LongAdder counter = new LongAdder();
    SplittableRandom r = new SplittableRandom();
    long size = 100;
    r.doubles().limit(size).parallel().forEach(x -> counter.increment());
    assertEquals(size, counter.sum());
}
Also used : LongAdder(java8.util.concurrent.atomic.LongAdder) SplittableRandom(java8.util.SplittableRandom)

Example 40 with LongAdder

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

the class SplittableRandomTest method testUnsizedDoublesCountSeq.

/**
 * A sequential unsized stream of doubles generates at least 100 values
 */
public void testUnsizedDoublesCountSeq() {
    LongAdder counter = new LongAdder();
    SplittableRandom r = new SplittableRandom();
    long size = 100;
    r.doubles().limit(size).forEach(x -> counter.increment());
    assertEquals(size, counter.sum());
}
Also used : LongAdder(java8.util.concurrent.atomic.LongAdder) SplittableRandom(java8.util.SplittableRandom)

Aggregations

LongAdder (java8.util.concurrent.atomic.LongAdder)50 SplittableRandom (java8.util.SplittableRandom)18 ThreadLocalRandom (java8.util.concurrent.ThreadLocalRandom)18 DoubleConsumer (java8.util.function.DoubleConsumer)3 IntConsumer (java8.util.function.IntConsumer)3 LongConsumer (java8.util.function.LongConsumer)3 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 ExecutorService (java.util.concurrent.ExecutorService)1 Phaser (java8.util.concurrent.Phaser)1