Java Code Examples for java.util.concurrent.atomic.DoubleAdder

The following examples show how to use java.util.concurrent.atomic.DoubleAdder. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: j2objc   Source File: DoubleAdderTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * adds by multiple threads produce correct sum
 */
public void testAddAndSumMT() throws Throwable {
    final int incs = 1000000;
    final int nthreads = 4;
    final ExecutorService pool = Executors.newCachedThreadPool();
    DoubleAdder a = new DoubleAdder();
    CyclicBarrier barrier = new CyclicBarrier(nthreads + 1);
    for (int i = 0; i < nthreads; ++i)
        pool.execute(new AdderTask(a, barrier, incs));
    barrier.await();
    barrier.await();
    double total = (long)nthreads * incs;
    double sum = a.sum();
    assertEquals(sum, total);
    pool.shutdown();
}
 
Example 2
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());
}
 
Example 3
public void run() {
    phaser.arriveAndAwaitAdvance();
    phaser.arriveAndAwaitAdvance();
    DoubleAdder a = adder;
    for (int i = 0; i < incs; ++i)
        a.add(1.0);
    result = a.sum();
    phaser.arrive();
}
 
Example 4
Source Project: dragonwell8_jdk   Source File: Serial.java    License: GNU General Public License v2.0 5 votes vote down vote up
static void testDoubleAdder() {
    DoubleAdder a = new DoubleAdder();
    a.add(20.1d);
    DoubleAdder result = echo(a);
    if (result.doubleValue() != a.doubleValue())
        throw new RuntimeException("Unexpected doubleValue");

    checkSerialClassName(a, "java.util.concurrent.atomic.DoubleAdder$SerializationProxy");
}
 
Example 5
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());
}
 
Example 6
public void run() {
    phaser.arriveAndAwaitAdvance();
    phaser.arriveAndAwaitAdvance();
    DoubleAdder a = adder;
    for (int i = 0; i < incs; ++i)
        a.add(1.0);
    result = a.sum();
    phaser.arrive();
}
 
Example 7
Source Project: TencentKona-8   Source File: Serial.java    License: GNU General Public License v2.0 5 votes vote down vote up
static void testDoubleAdder() {
    DoubleAdder a = new DoubleAdder();
    a.add(20.1d);
    DoubleAdder result = echo(a);
    if (result.doubleValue() != a.doubleValue())
        throw new RuntimeException("Unexpected doubleValue");

    checkSerialClassName(a, "java.util.concurrent.atomic.DoubleAdder$SerializationProxy");
}
 
Example 8
Source Project: j2objc   Source File: DoubleAdderTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * reset() causes subsequent sum() to return zero
 */
public void testReset() {
    DoubleAdder ai = new DoubleAdder();
    ai.add(2.0);
    assertEquals(2.0, ai.sum());
    ai.reset();
    assertEquals(0.0, ai.sum());
}
 
Example 9
public void run() {
    phaser.arriveAndAwaitAdvance();
    phaser.arriveAndAwaitAdvance();
    DoubleAdder a = adder;
    for (int i = 0; i < incs; ++i)
        a.add(1.0);
    result = a.sum();
    phaser.arrive();
}
 
Example 10
Source Project: native-obfuscator   Source File: Serial.java    License: GNU General Public License v3.0 5 votes vote down vote up
static void testDoubleAdder() {
    DoubleAdder a = new DoubleAdder();
    a.add(20.1d);
    DoubleAdder result = echo(a);
    if (result.doubleValue() != a.doubleValue())
        throw new RuntimeException("Unexpected doubleValue");

    checkSerialClassName(a, "java.util.concurrent.atomic.DoubleAdder$SerializationProxy");
}
 
Example 11
Source Project: jdk8u60   Source File: DoubleAdderDemo.java    License: GNU General Public License v2.0 5 votes vote down vote up
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());
}
 
Example 12
Source Project: jdk8u60   Source File: DoubleAdderDemo.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void run() {
    phaser.arriveAndAwaitAdvance();
    phaser.arriveAndAwaitAdvance();
    DoubleAdder a = adder;
    for (int i = 0; i < incs; ++i)
        a.add(1.0);
    result = a.sum();
    phaser.arrive();
}
 
Example 13
Source Project: jdk8u60   Source File: Serial.java    License: GNU General Public License v2.0 5 votes vote down vote up
static void testDoubleAdder() {
    DoubleAdder a = new DoubleAdder();
    a.add(20.1d);
    DoubleAdder result = echo(a);
    if (result.doubleValue() != a.doubleValue())
        throw new RuntimeException("Unexpected doubleValue");

    checkSerialClassName(a, "java.util.concurrent.atomic.DoubleAdder$SerializationProxy");
}
 
Example 14
Source Project: coroutines   Source File: ForkJoinExample.java    License: Apache License 2.0 5 votes vote down vote up
/***************************************
 * Main.
 *
 * @param rArgs
 */
public static void main(String[] rArgs)
{
	ThreadLocalRandom rRandom	    = ThreadLocalRandom.current();
	long[]			  aCoefficients = new long[TASK_SIZE];

	for (int i = 0; i < TASK_SIZE; i++)
	{
		aCoefficients[i] = rRandom.nextLong(0, 1024 * 1024);
	}

	Profiler aProfiler =
		new Profiler(ForkJoinExample.class.getSimpleName());

	ScopeFuture<DoubleAdder> aResult =
		produce(
			RESULT,
			scope -> computeOrSplit(scope, aCoefficients, 0, TASK_SIZE));

	System.out.printf("Sum: %f\n", aResult.get().sum());

	aProfiler.measure(
		String.format(
			"%d tasks\nwith a batch size of %d",
			TASK_SIZE,
			BATCH_SIZE));
	aProfiler.printSummary();
}
 
Example 15
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());
}
 
Example 16
public void run() {
    phaser.arriveAndAwaitAdvance();
    phaser.arriveAndAwaitAdvance();
    DoubleAdder a = adder;
    for (int i = 0; i < incs; ++i)
        a.add(1.0);
    result = a.sum();
    phaser.arrive();
}
 
Example 17
Source Project: openjdk-jdk8u   Source File: Serial.java    License: GNU General Public License v2.0 5 votes vote down vote up
static void testDoubleAdder() {
    DoubleAdder a = new DoubleAdder();
    a.add(20.1d);
    DoubleAdder result = echo(a);
    if (result.doubleValue() != a.doubleValue())
        throw new RuntimeException("Unexpected doubleValue");

    checkSerialClassName(a, "java.util.concurrent.atomic.DoubleAdder$SerializationProxy");
}
 
Example 18
public FixedBoundaryVictoriaMetricsHistogram() {
    this.zeros = new AtomicLong(0);
    this.lower = new AtomicLong(0);
    this.upper = new AtomicLong(0);
    this.sum = new DoubleAdder();

    this.values = new AtomicReferenceArray<>(BUCKETS_COUNT);
}
 
Example 19
Source Project: micrometer   Source File: CumulativeDistributionSummary.java    License: Apache License 2.0 5 votes vote down vote up
public CumulativeDistributionSummary(Id id, Clock clock, DistributionStatisticConfig distributionStatisticConfig,
                                     double scale, boolean supportsAggregablePercentiles) {
    super(id, clock, distributionStatisticConfig, scale, supportsAggregablePercentiles);
    this.count = new AtomicLong();
    this.total = new DoubleAdder();
    this.max = new TimeWindowMax(clock, distributionStatisticConfig);
}
 
Example 20
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());
}
 
Example 21
Source Project: j2objc   Source File: DoubleAdderTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * floatValue returns current value.
 */
public void testFloatValue() {
    DoubleAdder ai = new DoubleAdder();
    assertEquals(0.0f, ai.floatValue());
    ai.add(1.0);
    assertEquals(1.0f, ai.floatValue());
}
 
Example 22
public void run() {
    phaser.arriveAndAwaitAdvance();
    phaser.arriveAndAwaitAdvance();
    DoubleAdder a = adder;
    for (int i = 0; i < incs; ++i)
        a.add(1.0);
    result = a.sum();
    phaser.arrive();
}
 
Example 23
Source Project: j2objc   Source File: DoubleAdderTest.java    License: Apache License 2.0 5 votes vote down vote up
public void run() {
    try {
        barrier.await();
        DoubleAdder a = adder;
        for (int i = 0; i < incs; ++i)
            a.add(1.0);
        result = a.sum();
        barrier.await();
    } catch (Throwable t) { throw new Error(t); }
}
 
Example 24
Source Project: openjdk-jdk9   Source File: DoubleAdderDemo.java    License: GNU General Public License v2.0 5 votes vote down vote up
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());
}
 
Example 25
Source Project: j2objc   Source File: DoubleAdderTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * intValue returns current value.
 */
public void testIntValue() {
    DoubleAdder ai = new DoubleAdder();
    assertEquals(0, ai.intValue());
    ai.add(1.0);
    assertEquals(1, ai.intValue());
}
 
Example 26
Source Project: openjdk-jdk9   Source File: Serial.java    License: GNU General Public License v2.0 5 votes vote down vote up
static void testDoubleAdder() {
    DoubleAdder a = new DoubleAdder();
    a.add(20.1d);
    DoubleAdder result = echo(a);
    if (result.doubleValue() != a.doubleValue())
        throw new RuntimeException("Unexpected doubleValue");

    checkSerialClassName(a, "java.util.concurrent.atomic.DoubleAdder$SerializationProxy");
}
 
Example 27
Source Project: openjdk-jdk9   Source File: DoubleAdderTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * reset() causes subsequent sum() to return zero
 */
public void testReset() {
    DoubleAdder ai = new DoubleAdder();
    ai.add(2.0);
    assertEquals(2.0, ai.sum());
    ai.reset();
    assertEquals(0.0, ai.sum());
}
 
Example 28
Source Project: openjdk-jdk9   Source File: DoubleAdderTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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());
}
 
Example 29
Source Project: j2objc   Source File: DoubleAdderTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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());
}
 
Example 30
Source Project: openjdk-jdk9   Source File: DoubleAdderTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * toString returns current value.
 */
public void testToString() {
    DoubleAdder ai = new DoubleAdder();
    assertEquals(Double.toString(0.0), ai.toString());
    ai.add(1.0);
    assertEquals(Double.toString(1.0), ai.toString());
}