當前位置: 首頁>>代碼示例>>Java>>正文


Java AtomicIntegerFieldUpdater.set方法代碼示例

本文整理匯總了Java中java.util.concurrent.atomic.AtomicIntegerFieldUpdater.set方法的典型用法代碼示例。如果您正苦於以下問題:Java AtomicIntegerFieldUpdater.set方法的具體用法?Java AtomicIntegerFieldUpdater.set怎麽用?Java AtomicIntegerFieldUpdater.set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.concurrent.atomic.AtomicIntegerFieldUpdater的用法示例。


在下文中一共展示了AtomicIntegerFieldUpdater.set方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testIntegerFieldUpdaterGetAndUpdate

import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; //導入方法依賴的package包/類
/**
 * 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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:13,代碼來源:Atomic8Test.java

示例2: testIntegerFieldUpdaterUpdateAndGet

import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; //導入方法依賴的package包/類
/**
 * 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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:13,代碼來源:Atomic8Test.java

示例3: testIntegerFieldUpdaterGetAndAccumulate

import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; //導入方法依賴的package包/類
/**
 * 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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:13,代碼來源:Atomic8Test.java

示例4: testIntegerFieldUpdaterAccumulateAndGet

import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; //導入方法依賴的package包/類
/**
 * 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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:13,代碼來源:Atomic8Test.java

示例5: testFieldUpdaters_ClassCastException

import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; //導入方法依賴的package包/類
/**
 * 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);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:36,代碼來源:Atomic8Test.java

示例6: testGetSet

import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; //導入方法依賴的package包/類
/**
 * 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));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:AtomicIntegerFieldUpdaterTest.java

示例7: testGetAndIncrement

import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; //導入方法依賴的package包/類
/**
 * 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));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:16,代碼來源:AtomicIntegerFieldUpdaterTest.java

示例8: testIncrementAndGet

import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; //導入方法依賴的package包/類
/**
 * 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));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:16,代碼來源:AtomicIntegerFieldUpdaterTest.java

示例9: should_pass_if_atomicIntegerFieldUpdater_contains_expected_value

import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; //導入方法依賴的package包/類
@Test
public void should_pass_if_atomicIntegerFieldUpdater_contains_expected_value() throws Exception {
  AtomicIntegerFieldUpdater<Person> fieldUpdater = AtomicIntegerFieldUpdater.newUpdater(Person.class, "age");
  fieldUpdater.set(person, 25);
  assertThat(fieldUpdater).hasValue(25, person);
}
 
開發者ID:joel-costigliola,項目名稱:assertj-core,代碼行數:7,代碼來源:AtomicIntegerFieldUpdater_hasValue_Test.java


注:本文中的java.util.concurrent.atomic.AtomicIntegerFieldUpdater.set方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。