当前位置: 首页>>代码示例>>Java>>正文


Java AtomicLongFieldUpdater.set方法代码示例

本文整理汇总了Java中java.util.concurrent.atomic.AtomicLongFieldUpdater.set方法的典型用法代码示例。如果您正苦于以下问题:Java AtomicLongFieldUpdater.set方法的具体用法?Java AtomicLongFieldUpdater.set怎么用?Java AtomicLongFieldUpdater.set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.atomic.AtomicLongFieldUpdater的用法示例。


在下文中一共展示了AtomicLongFieldUpdater.set方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testGetSet

import java.util.concurrent.atomic.AtomicLongFieldUpdater; //导入方法依赖的package包/类
/**
 * 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));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:AtomicLongFieldUpdaterTest.java

示例2: testGetAndIncrement

import java.util.concurrent.atomic.AtomicLongFieldUpdater; //导入方法依赖的package包/类
/**
 * 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));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:AtomicLongFieldUpdaterTest.java

示例3: testIncrementAndGet

import java.util.concurrent.atomic.AtomicLongFieldUpdater; //导入方法依赖的package包/类
/**
 * 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));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:AtomicLongFieldUpdaterTest.java

示例4: testLongFieldUpdaterGetAndUpdate

import java.util.concurrent.atomic.AtomicLongFieldUpdater; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:Atomic8Test.java

示例5: testLongFieldUpdaterUpdateAndGet

import java.util.concurrent.atomic.AtomicLongFieldUpdater; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:Atomic8Test.java

示例6: testLongFieldUpdaterGetAndAccumulate

import java.util.concurrent.atomic.AtomicLongFieldUpdater; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:Atomic8Test.java

示例7: testLongFieldUpdaterAccumulateAndGet

import java.util.concurrent.atomic.AtomicLongFieldUpdater; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:Atomic8Test.java

示例8: testFieldUpdaters_ClassCastException

import java.util.concurrent.atomic.AtomicLongFieldUpdater; //导入方法依赖的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

示例9: should_pass_if_atomicLongFieldUpdater_contains_expected_value

import java.util.concurrent.atomic.AtomicLongFieldUpdater; //导入方法依赖的package包/类
@Test
public void should_pass_if_atomicLongFieldUpdater_contains_expected_value() throws Exception {
  AtomicLongFieldUpdater<Person> fieldUpdater = AtomicLongFieldUpdater.newUpdater(Person.class, "age");
  fieldUpdater.set(person, 25);
  assertThat(fieldUpdater).hasValue(25L, person);
}
 
开发者ID:joel-costigliola,项目名称:assertj-core,代码行数:7,代码来源:AtomicLongFieldUpdater_hasValue_Test.java


注:本文中的java.util.concurrent.atomic.AtomicLongFieldUpdater.set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。