當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。