Search in sources :

Example 56 with LongAdder

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

the class LongAdderTest method test_long_add.

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

Example 57 with LongAdder

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

the class CounterServiceSpeedTests 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.counters.forEach(Pattern.compile(name).asPredicate(), new BiConsumer<String, CounterBuffer>() {

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

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

Example 58 with LongAdder

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

the class DefaultCounterServiceSpeedTests method counters.

@Theory
public void counters(String input) throws Exception {
    watch.start("counters" + count++);
    ExecutorService pool = Executors.newFixedThreadPool(threadCount);
    Runnable task = new Runnable() {

        @Override
        public void run() {
            for (int i = 0; i < number; i++) {
                String name = sample[i % sample.length];
                DefaultCounterServiceSpeedTests.this.counterService.increment(name);
            }
        }
    };
    Collection<Future<?>> futures = new HashSet<>();
    for (int i = 0; i < threadCount; i++) {
        futures.add(pool.submit(task));
    }
    for (Future<?> future : futures) {
        future.get();
    }
    watch.stop();
    double rate = number / watch.getLastTaskTimeMillis() * 1000;
    System.err.println("Counters rate(" + count + ")=" + rate + ", " + watch);
    watch.start("read" + count);
    this.reader.findAll().forEach(new Consumer<Metric<?>>() {

        @Override
        public void accept(Metric<?> metric) {
            err.println(metric);
        }
    });
    final LongAdder total = new LongAdder();
    this.reader.findAll().forEach(new Consumer<Metric<?>>() {

        @Override
        public void accept(Metric<?> value) {
            total.add(value.getValue().intValue());
        }
    });
    watch.stop();
    System.err.println("Read(" + count + ")=" + watch.getLastTaskTimeMillis() + "ms");
    assertThat(total.longValue()).isEqualTo(number * threadCount);
}
Also used : LongAdder(java.util.concurrent.atomic.LongAdder) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) Metric(org.springframework.boot.actuate.metrics.Metric) HashSet(java.util.HashSet) Theory(org.junit.experimental.theories.Theory)

Example 59 with LongAdder

use of java.util.concurrent.atomic.LongAdder in project intellij-community by JetBrains.

the class Main10 method m.

void m() {
    LongAdder l = new LongAdder();
    String asString = l.toString();
    l.add(123);
}
Also used : LongAdder(java.util.concurrent.atomic.LongAdder)

Example 60 with LongAdder

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

the class RandomTest method testUnsizedLongsCountSeq.

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

Aggregations

LongAdder (java.util.concurrent.atomic.LongAdder)92 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)16 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)16 Random (java.util.Random)13 ExecutorService (java.util.concurrent.ExecutorService)10 SplittableRandom (java.util.SplittableRandom)9 HashMap (java.util.HashMap)7 Map (java.util.Map)6 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 Theory (org.junit.experimental.theories.Theory)6 UUID (java.util.UUID)5 ArrayList (java.util.ArrayList)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 Ignite (org.apache.ignite.Ignite)4 IgniteUuid (org.apache.ignite.lang.IgniteUuid)4 Metric (org.springframework.boot.actuate.metrics.Metric)4 Date (java.util.Date)3 HashSet (java.util.HashSet)3 Callable (java.util.concurrent.Callable)3 CountDownLatch (java.util.concurrent.CountDownLatch)3