Search in sources :

Example 26 with LongAdder

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

the class RandomTest method testUnsizedIntsCountSeq.

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

Example 27 with LongAdder

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

the class RandomTest method testLongsCount.

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

Example 28 with LongAdder

use of java.util.concurrent.atomic.LongAdder in project XRTB by benmfaul.

the class CampaignProbe method reset.

public void reset() {
    for (Map.Entry<String, CreativeProbe> entry : probes.entrySet()) {
        entry.getValue().reset();
    }
    total = new LongAdder();
    bids = new LongAdder();
}
Also used : LongAdder(java.util.concurrent.atomic.LongAdder) Map(java.util.Map) HashMap(java.util.HashMap)

Example 29 with LongAdder

use of java.util.concurrent.atomic.LongAdder in project XRTB by benmfaul.

the class CreativeProbe method report.

public String report() {
    StringBuilder report = new StringBuilder();
    report.append("\t\t\ttotal = ");
    report.append(total.sum());
    report.append(", bids = ");
    report.append("\n");
    for (Map.Entry<String, LongAdder> entry : probes.entrySet()) {
        String key = entry.getKey();
        report.append("\t\t\t");
        report.append(key);
        report.append(" = ");
        LongAdder ad = entry.getValue();
        report.append(ad.sum());
        report.append(",   (");
        double v = total.sum();
        double vx = ad.sum();
        report.append(100 * vx / v);
        report.append(")\n");
    }
    return report.toString();
}
Also used : LongAdder(java.util.concurrent.atomic.LongAdder) Map(java.util.Map) HashMap(java.util.HashMap)

Example 30 with LongAdder

use of java.util.concurrent.atomic.LongAdder in project mapdb by jankotek.

the class ConcurrentHashMap8Test method testMappedForEachEntrySequentially.

/**
     * Mapped forEachEntrySequentially traverses the given
     * transformations of all entries
     */
public void testMappedForEachEntrySequentially() {
    LongAdder adder = new LongAdder();
    ConcurrentHashMap<Long, Long> m = longMap();
    m.forEachEntry(Long.MAX_VALUE, (Map.Entry<Long, Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()), (Long x) -> adder.add(x.longValue()));
    assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
}
Also used : LongAdder(java.util.concurrent.atomic.LongAdder)

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