java.util.concurrent.atomic.AtomicIntegerFieldUpdater

Here are the examples of the java api class java.util.concurrent.atomic.AtomicIntegerFieldUpdater taken from open source projects.

1. Atomic8Test#testIntegerFieldUpdaterGetAndUpdate()

Project: openjdk
Source File: Atomic8Test.java
View license
/**
     * 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);
}

2. Atomic8Test#testIntegerFieldUpdaterUpdateAndGet()

Project: openjdk
Source File: Atomic8Test.java
View license
/**
     * 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);
}

3. Atomic8Test#testIntegerFieldUpdaterGetAndAccumulate()

Project: openjdk
Source File: Atomic8Test.java
View license
/**
     * 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);
}

4. Atomic8Test#testIntegerFieldUpdaterAccumulateAndGet()

Project: openjdk
Source File: Atomic8Test.java
View license
/**
     * 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);
}