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


Java AtomicLongFieldUpdater类代码示例

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


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

示例1: testCompareAndSetInMultipleThreads

import java.util.concurrent.atomic.AtomicLongFieldUpdater; //导入依赖的package包/类
/**
 * compareAndSet in one thread enables another waiting for value
 * to succeed
 */
public void testCompareAndSetInMultipleThreads() throws Exception {
    x = 1;
    final AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a;
    a = updaterFor("x");

    Thread t = new Thread(new CheckedRunnable() {
        public void realRun() {
            while (!a.compareAndSet(AtomicLongFieldUpdaterTest.this, 2, 3))
                Thread.yield();
        }});

    t.start();
    assertTrue(a.compareAndSet(this, 1, 2));
    t.join(LONG_DELAY_MS);
    assertFalse(t.isAlive());
    assertEquals(3, a.get(this));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:AtomicLongFieldUpdaterTest.java

示例2: producedCancellable

import java.util.concurrent.atomic.AtomicLongFieldUpdater; //导入依赖的package包/类
static <T> long producedCancellable(AtomicLongFieldUpdater<T> updater, T instance, long n) {
	for (; ; ) {
		long current = updater.get(instance);
		if (current == Long.MIN_VALUE) {
			return Long.MIN_VALUE;
		}
		if (current == Long.MAX_VALUE) {
			return Long.MAX_VALUE;
		}
		long update = current - n;
		if (update < 0L) {
			reportBadRequest(update);
			update = 0L;
		}
		if (updater.compareAndSet(instance, current, update)) {
			return update;
		}
	}
}
 
开发者ID:reactor,项目名称:reactor-core,代码行数:20,代码来源:Operators.java

示例3: getAndAddRequest

import java.util.concurrent.atomic.AtomicLongFieldUpdater; //导入依赖的package包/类
public static <T> long getAndAddRequest(AtomicLongFieldUpdater<T> requested, T object, long n) {
    long current;
    do {
        current = requested.get(object);
    } while (!requested.compareAndSet(object, current, addCap(current, n)));
    return current;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:8,代码来源:BackpressureUtils.java

示例4: checkPrivateAccess

import java.util.concurrent.atomic.AtomicLongFieldUpdater; //导入依赖的package包/类
public void checkPrivateAccess() {
    try {
        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a =
            AtomicLongFieldUpdater.newUpdater
            (AtomicLongFieldUpdaterTest.class, "privateField");
        shouldThrow();
    } catch (RuntimeException success) {
        assertNotNull(success.getCause());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:AtomicLongFieldUpdaterTest.java

示例5: checkCompareAndSetProtectedSub

import java.util.concurrent.atomic.AtomicLongFieldUpdater; //导入依赖的package包/类
public void checkCompareAndSetProtectedSub() {
    AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a =
        AtomicLongFieldUpdater.newUpdater
        (AtomicLongFieldUpdaterTest.class, "protectedField");
    this.protectedField = 1;
    assertTrue(a.compareAndSet(this, 1, 2));
    assertTrue(a.compareAndSet(this, 2, -4));
    assertEquals(-4, a.get(this));
    assertFalse(a.compareAndSet(this, -5, 7));
    assertEquals(-4, a.get(this));
    assertTrue(a.compareAndSet(this, -4, 7));
    assertEquals(7, a.get(this));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:AtomicLongFieldUpdaterTest.java

示例6: checkPackageAccess

import java.util.concurrent.atomic.AtomicLongFieldUpdater; //导入依赖的package包/类
public void checkPackageAccess(AtomicLongFieldUpdaterTest obj) {
    obj.x = 72L;
    AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a =
        AtomicLongFieldUpdater.newUpdater
        (AtomicLongFieldUpdaterTest.class, "x");
    assertEquals(72L, a.get(obj));
    assertTrue(a.compareAndSet(obj, 72L, 73L));
    assertEquals(73L, a.get(obj));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:AtomicLongFieldUpdaterTest.java

示例7: 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

示例8: testGetLazySet

import java.util.concurrent.atomic.AtomicLongFieldUpdater; //导入依赖的package包/类
/**
 * get returns the last value lazySet by same thread
 */
public void testGetLazySet() {
    AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a;
    a = updaterFor("x");
    x = 1;
    assertEquals(1, a.get(this));
    a.lazySet(this, 2);
    assertEquals(2, a.get(this));
    a.lazySet(this, -3);
    assertEquals(-3, a.get(this));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:AtomicLongFieldUpdaterTest.java

示例9: testCompareAndSet

import java.util.concurrent.atomic.AtomicLongFieldUpdater; //导入依赖的package包/类
/**
 * compareAndSet succeeds in changing value if equal to expected else fails
 */
public void testCompareAndSet() {
    AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a;
    a = updaterFor("x");
    x = 1;
    assertTrue(a.compareAndSet(this, 1, 2));
    assertTrue(a.compareAndSet(this, 2, -4));
    assertEquals(-4, a.get(this));
    assertFalse(a.compareAndSet(this, -5, 7));
    assertEquals(-4, a.get(this));
    assertTrue(a.compareAndSet(this, -4, 7));
    assertEquals(7, a.get(this));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:AtomicLongFieldUpdaterTest.java

示例10: testCompareAndSetProtected

import java.util.concurrent.atomic.AtomicLongFieldUpdater; //导入依赖的package包/类
/**
 * compareAndSet succeeds in changing protected field value if
 * equal to expected else fails
 */
public void testCompareAndSetProtected() {
    AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a;
    a = updaterFor("protectedField");
    protectedField = 1;
    assertTrue(a.compareAndSet(this, 1, 2));
    assertTrue(a.compareAndSet(this, 2, -4));
    assertEquals(-4, a.get(this));
    assertFalse(a.compareAndSet(this, -5, 7));
    assertEquals(-4, a.get(this));
    assertTrue(a.compareAndSet(this, -4, 7));
    assertEquals(7, a.get(this));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:AtomicLongFieldUpdaterTest.java

示例11: testWeakCompareAndSet

import java.util.concurrent.atomic.AtomicLongFieldUpdater; //导入依赖的package包/类
/**
 * repeated weakCompareAndSet succeeds in changing value when equal
 * to expected
 */
public void testWeakCompareAndSet() {
    AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a;
    a = updaterFor("x");
    x = 1;
    do {} while (!a.weakCompareAndSet(this, 1, 2));
    do {} while (!a.weakCompareAndSet(this, 2, -4));
    assertEquals(-4, a.get(this));
    do {} while (!a.weakCompareAndSet(this, -4, 7));
    assertEquals(7, a.get(this));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:AtomicLongFieldUpdaterTest.java

示例12: testGetAndSet

import java.util.concurrent.atomic.AtomicLongFieldUpdater; //导入依赖的package包/类
/**
 * getAndSet returns previous value and sets to given value
 */
public void testGetAndSet() {
    AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a;
    a = updaterFor("x");
    x = 1;
    assertEquals(1, a.getAndSet(this, 0));
    assertEquals(0, a.getAndSet(this, -10));
    assertEquals(-10, a.getAndSet(this, 1));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:AtomicLongFieldUpdaterTest.java

示例13: testGetAndAdd

import java.util.concurrent.atomic.AtomicLongFieldUpdater; //导入依赖的package包/类
/**
 * getAndAdd returns previous value and adds given value
 */
public void testGetAndAdd() {
    AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a;
    a = updaterFor("x");
    x = 1;
    assertEquals(1, a.getAndAdd(this, 2));
    assertEquals(3, a.get(this));
    assertEquals(3, a.getAndAdd(this, -4));
    assertEquals(-1, a.get(this));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:AtomicLongFieldUpdaterTest.java

示例14: testGetAndDecrement

import java.util.concurrent.atomic.AtomicLongFieldUpdater; //导入依赖的package包/类
/**
 * getAndDecrement returns previous value and decrements
 */
public void testGetAndDecrement() {
    AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a;
    a = updaterFor("x");
    x = 1;
    assertEquals(1, a.getAndDecrement(this));
    assertEquals(0, a.getAndDecrement(this));
    assertEquals(-1, a.getAndDecrement(this));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:AtomicLongFieldUpdaterTest.java

示例15: 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


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