Search in sources :

Example 16 with LongAdder

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

the class SplittableRandomTest method testIntsCount.

/**
     * A parallel sized stream of ints generates the given number of values
     */
public void testIntsCount() {
    LongAdder counter = new LongAdder();
    SplittableRandom r = new SplittableRandom();
    long size = 0;
    for (int reps = 0; reps < REPS; ++reps) {
        counter.reset();
        r.ints(size).parallel().forEach(x -> {
            counter.increment();
        });
        assertEquals(counter.sum(), size);
        size += 524959;
    }
}
Also used : LongAdder(java.util.concurrent.atomic.LongAdder) SplittableRandom(java.util.SplittableRandom)

Example 17 with LongAdder

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

the class SplittableRandomTest method testDoublesCount.

/**
     * A parallel sized stream of doubles generates the given number of values
     */
public void testDoublesCount() {
    LongAdder counter = new LongAdder();
    SplittableRandom r = new SplittableRandom();
    long size = 0;
    for (int reps = 0; reps < REPS; ++reps) {
        counter.reset();
        r.doubles(size).parallel().forEach(x -> {
            counter.increment();
        });
        assertEquals(counter.sum(), size);
        size += 524959;
    }
}
Also used : LongAdder(java.util.concurrent.atomic.LongAdder) SplittableRandom(java.util.SplittableRandom)

Example 18 with LongAdder

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

the class ThreadLocalRandomTest method testDoublesCount.

/**
     * A parallel sized stream of doubles generates the given number of values
     */
public void testDoublesCount() {
    LongAdder counter = new LongAdder();
    ThreadLocalRandom r = ThreadLocalRandom.current();
    long size = 0;
    for (int reps = 0; reps < REPS; ++reps) {
        counter.reset();
        r.doubles(size).parallel().forEach(x -> {
            counter.increment();
        });
        assertEquals(counter.sum(), size);
        size += 524959;
    }
}
Also used : LongAdder(java.util.concurrent.atomic.LongAdder) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom)

Example 19 with LongAdder

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

the class ThreadLocalRandomTest method testUnsizedIntsCountSeq.

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

Example 20 with LongAdder

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

the class ThreadLocalRandomTest method testUnsizedLongsCount.

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

Aggregations

LongAdder (java.util.concurrent.atomic.LongAdder)65 Random (java.util.Random)9 SplittableRandom (java.util.SplittableRandom)9 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)9 HashMap (java.util.HashMap)6 Theory (org.junit.experimental.theories.Theory)6 Map (java.util.Map)5 Metric (org.springframework.boot.actuate.metrics.Metric)5 HashSet (java.util.HashSet)3 ExecutorService (java.util.concurrent.ExecutorService)3 Future (java.util.concurrent.Future)3 ConcurrentModificationException (java.util.ConcurrentModificationException)2 NoSuchElementException (java.util.NoSuchElementException)2 Set (java.util.Set)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Deferred (org.osgi.util.promise.Deferred)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1