Java Code Examples for java.util.concurrent.atomic.AtomicIntegerFieldUpdater#set()
The following examples show how to use
java.util.concurrent.atomic.AtomicIntegerFieldUpdater#set() .
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: Atomic8Test.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * AtomicIntegerFieldUpdater getAndUpdate returns previous value and updates * result of supplied function */ public void testIntegerFieldUpdaterGetAndUpdate() { AtomicIntegerFieldUpdater a = anIntFieldUpdater(); a.set(this, 1); assertEquals(1, a.getAndUpdate(this, Atomic8Test::addInt17)); assertEquals(18, a.getAndUpdate(this, Atomic8Test::addInt17)); assertEquals(35, a.get(this)); assertEquals(35, anIntField); }
Example 2
Source File: Atomic8Test.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * AtomicIntegerFieldUpdater updateAndGet updates with supplied function and * returns result. */ public void testIntegerFieldUpdaterUpdateAndGet() { AtomicIntegerFieldUpdater a = anIntFieldUpdater(); a.set(this, 1); assertEquals(18, a.updateAndGet(this, Atomic8Test::addInt17)); assertEquals(35, a.updateAndGet(this, Atomic8Test::addInt17)); assertEquals(35, a.get(this)); assertEquals(35, anIntField); }
Example 3
Source File: Atomic8Test.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * AtomicIntegerFieldUpdater getAndAccumulate returns previous value * and updates with supplied function. */ public void testIntegerFieldUpdaterGetAndAccumulate() { AtomicIntegerFieldUpdater a = anIntFieldUpdater(); a.set(this, 1); assertEquals(1, a.getAndAccumulate(this, 2, Integer::sum)); assertEquals(3, a.getAndAccumulate(this, 3, Integer::sum)); assertEquals(6, a.get(this)); assertEquals(6, anIntField); }
Example 4
Source File: Atomic8Test.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * AtomicIntegerFieldUpdater accumulateAndGet updates with supplied * function and returns result. */ public void testIntegerFieldUpdaterAccumulateAndGet() { AtomicIntegerFieldUpdater a = anIntFieldUpdater(); a.set(this, 1); assertEquals(7, a.accumulateAndGet(this, 6, Integer::sum)); assertEquals(10, a.accumulateAndGet(this, 3, Integer::sum)); assertEquals(10, a.get(this)); assertEquals(10, anIntField); }
Example 5
Source File: Atomic8Test.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Object arguments for parameters of type T that are not * instances of the class passed to the newUpdater call will * result in a ClassCastException being thrown. */ public void testFieldUpdaters_ClassCastException() { // Use raw types to allow passing wrong object type, provoking CCE final AtomicLongFieldUpdater longUpdater = aLongFieldUpdater(); final AtomicIntegerFieldUpdater intUpdater = anIntFieldUpdater(); final AtomicReferenceFieldUpdater refUpdater = anIntegerFieldUpdater(); final Object obj = new Object(); for (Object x : new Object[]{ new Object(), null }) { Runnable[] throwingActions = { () -> longUpdater.get(x), () -> intUpdater.get(x), () -> refUpdater.get(x), () -> longUpdater.set(x, 17L), () -> intUpdater.set(x, 17), () -> refUpdater.set(x, (Integer) 17), () -> longUpdater.addAndGet(x, 17L), () -> intUpdater.addAndGet(x, 17), () -> longUpdater.getAndUpdate(x, y -> y), () -> intUpdater.getAndUpdate(x, y -> y), () -> refUpdater.getAndUpdate(x, y -> y), () -> longUpdater.compareAndSet(x, 17L, 42L), () -> intUpdater.compareAndSet(x, 17, 42), () -> refUpdater.compareAndSet(x, (Integer) 17, (Integer) 42), }; assertThrows(ClassCastException.class, throwingActions); } }
Example 6
Source File: AtomicIntegerFieldUpdaterTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * get returns the last value set or assigned */ public void testGetSet() { AtomicIntegerFieldUpdater<AtomicIntegerFieldUpdaterTest> a; a = updaterFor("x"); x = 1; assertEquals(1, a.get(this)); a.set(this, 2); assertEquals(2, a.get(this)); a.set(this, -3); assertEquals(-3, a.get(this)); }
Example 7
Source File: AtomicIntegerFieldUpdaterTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * getAndIncrement returns previous value and increments */ public void testGetAndIncrement() { AtomicIntegerFieldUpdater<AtomicIntegerFieldUpdaterTest> a; a = updaterFor("x"); x = 1; assertEquals(1, a.getAndIncrement(this)); assertEquals(2, a.get(this)); a.set(this, -2); assertEquals(-2, a.getAndIncrement(this)); assertEquals(-1, a.getAndIncrement(this)); assertEquals(0, a.getAndIncrement(this)); assertEquals(1, a.get(this)); }
Example 8
Source File: AtomicIntegerFieldUpdaterTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * incrementAndGet increments and returns current value */ public void testIncrementAndGet() { AtomicIntegerFieldUpdater<AtomicIntegerFieldUpdaterTest> a; a = updaterFor("x"); x = 1; assertEquals(2, a.incrementAndGet(this)); assertEquals(2, a.get(this)); a.set(this, -2); assertEquals(-1, a.incrementAndGet(this)); assertEquals(0, a.incrementAndGet(this)); assertEquals(1, a.incrementAndGet(this)); assertEquals(1, a.get(this)); }
Example 9
Source File: Atomic8Test.java From j2objc with Apache License 2.0 | 5 votes |
/** * AtomicIntegerFieldUpdater getAndUpdate returns previous value and updates * result of supplied function */ public void testIntegerFieldUpdaterGetAndUpdate() { AtomicIntegerFieldUpdater a = anIntFieldUpdater(); a.set(this, 1); assertEquals(1, a.getAndUpdate(this, Atomic8Test::addInt17)); assertEquals(18, a.getAndUpdate(this, Atomic8Test::addInt17)); assertEquals(35, a.get(this)); assertEquals(35, anIntField); }
Example 10
Source File: Atomic8Test.java From j2objc with Apache License 2.0 | 5 votes |
/** * AtomicIntegerFieldUpdater updateAndGet updates with supplied function and * returns result. */ public void testIntegerFieldUpdaterUpdateAndGet() { AtomicIntegerFieldUpdater a = anIntFieldUpdater(); a.set(this, 1); assertEquals(18, a.updateAndGet(this, Atomic8Test::addInt17)); assertEquals(35, a.updateAndGet(this, Atomic8Test::addInt17)); assertEquals(35, a.get(this)); assertEquals(35, anIntField); }
Example 11
Source File: Atomic8Test.java From j2objc with Apache License 2.0 | 5 votes |
/** * AtomicIntegerFieldUpdater getAndAccumulate returns previous value * and updates with supplied function. */ public void testIntegerFieldUpdaterGetAndAccumulate() { AtomicIntegerFieldUpdater a = anIntFieldUpdater(); a.set(this, 1); assertEquals(1, a.getAndAccumulate(this, 2, Integer::sum)); assertEquals(3, a.getAndAccumulate(this, 3, Integer::sum)); assertEquals(6, a.get(this)); assertEquals(6, anIntField); }
Example 12
Source File: Atomic8Test.java From j2objc with Apache License 2.0 | 5 votes |
/** * AtomicIntegerFieldUpdater accumulateAndGet updates with supplied * function and returns result. */ public void testIntegerFieldUpdaterAccumulateAndGet() { AtomicIntegerFieldUpdater a = anIntFieldUpdater(); a.set(this, 1); assertEquals(7, a.accumulateAndGet(this, 6, Integer::sum)); assertEquals(10, a.accumulateAndGet(this, 3, Integer::sum)); assertEquals(10, a.get(this)); assertEquals(10, anIntField); }
Example 13
Source File: AtomicIntegerFieldUpdaterTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * get returns the last value set or assigned */ public void testGetSet() { AtomicIntegerFieldUpdater<AtomicIntegerFieldUpdaterTest> a; a = updaterFor("x"); x = 1; assertEquals(1, a.get(this)); a.set(this, 2); assertEquals(2, a.get(this)); a.set(this, -3); assertEquals(-3, a.get(this)); }
Example 14
Source File: AtomicIntegerFieldUpdaterTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * getAndIncrement returns previous value and increments */ public void testGetAndIncrement() { AtomicIntegerFieldUpdater<AtomicIntegerFieldUpdaterTest> a; a = updaterFor("x"); x = 1; assertEquals(1, a.getAndIncrement(this)); assertEquals(2, a.get(this)); a.set(this, -2); assertEquals(-2, a.getAndIncrement(this)); assertEquals(-1, a.getAndIncrement(this)); assertEquals(0, a.getAndIncrement(this)); assertEquals(1, a.get(this)); }
Example 15
Source File: AtomicIntegerFieldUpdaterTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * incrementAndGet increments and returns current value */ public void testIncrementAndGet() { AtomicIntegerFieldUpdater<AtomicIntegerFieldUpdaterTest> a; a = updaterFor("x"); x = 1; assertEquals(2, a.incrementAndGet(this)); assertEquals(2, a.get(this)); a.set(this, -2); assertEquals(-1, a.incrementAndGet(this)); assertEquals(0, a.incrementAndGet(this)); assertEquals(1, a.incrementAndGet(this)); assertEquals(1, a.get(this)); }