Java Code Examples for java.util.concurrent.atomic.AtomicLongFieldUpdater#set()
The following examples show how to use
java.util.concurrent.atomic.AtomicLongFieldUpdater#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: AtomicLongFieldUpdaterTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * get returns the last value set or assigned */ public void testGetSet() { AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> 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 2
Source File: AtomicLongFieldUpdaterTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * getAndIncrement returns previous value and increments */ public void testGetAndIncrement() { AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> 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 3
Source File: AtomicLongFieldUpdaterTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * incrementAndGet increments and returns current value */ public void testIncrementAndGet() { AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> 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 4
Source File: Atomic8Test.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * AtomicLongFieldUpdater getAndUpdate returns previous value and updates * result of supplied function */ public void testLongFieldUpdaterGetAndUpdate() { AtomicLongFieldUpdater a = aLongFieldUpdater(); a.set(this, 1); assertEquals(1L, a.getAndUpdate(this, Atomic8Test::addLong17)); assertEquals(18L, a.getAndUpdate(this, Atomic8Test::addLong17)); assertEquals(35L, a.get(this)); assertEquals(35L, aLongField); }
Example 5
Source File: Atomic8Test.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * AtomicLongFieldUpdater updateAndGet updates with supplied function and * returns result. */ public void testLongFieldUpdaterUpdateAndGet() { AtomicLongFieldUpdater a = aLongFieldUpdater(); a.set(this, 1); assertEquals(18L, a.updateAndGet(this, Atomic8Test::addLong17)); assertEquals(35L, a.updateAndGet(this, Atomic8Test::addLong17)); assertEquals(35L, a.get(this)); assertEquals(35L, aLongField); }
Example 6
Source File: Atomic8Test.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * AtomicLongFieldUpdater getAndAccumulate returns previous value * and updates with supplied function. */ public void testLongFieldUpdaterGetAndAccumulate() { AtomicLongFieldUpdater a = aLongFieldUpdater(); a.set(this, 1); assertEquals(1L, a.getAndAccumulate(this, 2L, Long::sum)); assertEquals(3L, a.getAndAccumulate(this, 3L, Long::sum)); assertEquals(6L, a.get(this)); assertEquals(6L, aLongField); }
Example 7
Source File: Atomic8Test.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * AtomicLongFieldUpdater accumulateAndGet updates with supplied * function and returns result. */ public void testLongFieldUpdaterAccumulateAndGet() { AtomicLongFieldUpdater a = aLongFieldUpdater(); a.set(this, 1); assertEquals(7L, a.accumulateAndGet(this, 6L, Long::sum)); assertEquals(10L, a.accumulateAndGet(this, 3L, Long::sum)); assertEquals(10L, a.get(this)); assertEquals(10L, aLongField); }
Example 8
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 9
Source File: AtomicLongFieldUpdaterTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * get returns the last value set or assigned */ public void testGetSet() { AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> 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 10
Source File: AtomicLongFieldUpdaterTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * getAndIncrement returns previous value and increments */ public void testGetAndIncrement() { AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> 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 11
Source File: AtomicLongFieldUpdaterTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * incrementAndGet increments and returns current value */ public void testIncrementAndGet() { AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> 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 12
Source File: Atomic8Test.java From j2objc with Apache License 2.0 | 5 votes |
/** * AtomicLongFieldUpdater getAndUpdate returns previous value and updates * result of supplied function */ public void testLongFieldUpdaterGetAndUpdate() { AtomicLongFieldUpdater a = aLongFieldUpdater(); a.set(this, 1); assertEquals(1L, a.getAndUpdate(this, Atomic8Test::addLong17)); assertEquals(18L, a.getAndUpdate(this, Atomic8Test::addLong17)); assertEquals(35L, a.get(this)); assertEquals(35L, aLongField); }
Example 13
Source File: Atomic8Test.java From j2objc with Apache License 2.0 | 5 votes |
/** * AtomicLongFieldUpdater updateAndGet updates with supplied function and * returns result. */ public void testLongFieldUpdaterUpdateAndGet() { AtomicLongFieldUpdater a = aLongFieldUpdater(); a.set(this, 1); assertEquals(18L, a.updateAndGet(this, Atomic8Test::addLong17)); assertEquals(35L, a.updateAndGet(this, Atomic8Test::addLong17)); assertEquals(35L, a.get(this)); assertEquals(35L, aLongField); }
Example 14
Source File: Atomic8Test.java From j2objc with Apache License 2.0 | 5 votes |
/** * AtomicLongFieldUpdater getAndAccumulate returns previous value * and updates with supplied function. */ public void testLongFieldUpdaterGetAndAccumulate() { AtomicLongFieldUpdater a = aLongFieldUpdater(); a.set(this, 1); assertEquals(1L, a.getAndAccumulate(this, 2L, Long::sum)); assertEquals(3L, a.getAndAccumulate(this, 3L, Long::sum)); assertEquals(6L, a.get(this)); assertEquals(6L, aLongField); }
Example 15
Source File: Atomic8Test.java From j2objc with Apache License 2.0 | 5 votes |
/** * AtomicLongFieldUpdater accumulateAndGet updates with supplied * function and returns result. */ public void testLongFieldUpdaterAccumulateAndGet() { AtomicLongFieldUpdater a = aLongFieldUpdater(); a.set(this, 1); assertEquals(7L, a.accumulateAndGet(this, 6L, Long::sum)); assertEquals(10L, a.accumulateAndGet(this, 3L, Long::sum)); assertEquals(10L, a.get(this)); assertEquals(10L, aLongField); }