java.util.concurrent.atomic.DoubleAdder Java Examples
The following examples show how to use
java.util.concurrent.atomic.DoubleAdder.
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 File: DoubleAdderTest.java From j2objc with Apache License 2.0 | 6 votes |
/** * 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
Source File: DoubleAdderDemo.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
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 #3
Source File: Serial.java From hottub with GNU General Public License v2.0 | 5 votes |
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 #4
Source File: Serial.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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
Source File: DoubleAdderTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * 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()); }
Example #6
Source File: DoubleAdderDemo.java From hottub with GNU General Public License v2.0 | 5 votes |
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 #7
Source File: AdderSerializer.java From uavstack with Apache License 2.0 | 5 votes |
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException { SerializeWriter out = serializer.out; if (object instanceof LongAdder) { out.writeFieldValue('{', "value", ((LongAdder) object).longValue()); out.write('}'); } else if (object instanceof DoubleAdder) { out.writeFieldValue('{', "value", ((DoubleAdder) object).doubleValue()); out.write('}'); } }
Example #8
Source File: DoubleAdderDemo.java From hottub with GNU General Public License v2.0 | 5 votes |
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 #9
Source File: DoubleAdderDemo.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
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 File: Serial.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
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 File: DoubleAdderDemo.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
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 File: DoubleAdderDemo.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
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 File: DoubleAdderDemo.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
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 #14
Source File: Serial.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
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 #15
Source File: DoubleAdderDemo.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
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
Source File: Serial.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
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 #17
Source File: Serial.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
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
Source File: DoubleAdderDemo.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
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 #19
Source File: DoubleAdderDemo.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
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 #20
Source File: DoubleAdderTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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 #21
Source File: DoubleAdderTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * a deserialized serialized adder holds same value */ public void testSerialization() throws Exception { DoubleAdder x = new DoubleAdder(); DoubleAdder y = serialClone(x); assertNotSame(x, y); x.add(-22.0); DoubleAdder z = serialClone(x); assertEquals(-22.0, x.sum()); assertEquals(0.0, y.sum()); assertEquals(-22.0, z.sum()); }
Example #22
Source File: Serial.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
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 #23
Source File: DoubleAdderTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * 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 #24
Source File: DoubleAdderTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * longValue returns current value. */ public void testLongValue() { DoubleAdder ai = new DoubleAdder(); assertEquals(0, ai.longValue()); ai.add(1.0); assertEquals(1, ai.longValue()); }
Example #25
Source File: DoubleAdderTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * 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 File: DoubleAdderTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * 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()); }
Example #27
Source File: DoubleAdderTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * 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 #28
Source File: DoubleAdderTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * 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 File: DoubleAdderTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * 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 #30
Source File: DoubleAdderTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * doubleValue returns current value. */ public void testDoubleValue() { DoubleAdder ai = new DoubleAdder(); assertEquals(0.0, ai.doubleValue()); ai.add(1.0); assertEquals(1.0, ai.doubleValue()); }