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


Java AtomicLongArray.set方法代碼示例

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


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

示例1: deserialze

import java.util.concurrent.atomic.AtomicLongArray; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
    if (parser.getLexer().token() == JSONToken.NULL) {
        parser.getLexer().nextToken(JSONToken.COMMA);
        return null;
    }

    JSONArray array = new JSONArray();
    parser.parseArray(array);

    AtomicLongArray atomicArray = new AtomicLongArray(array.size());
    for (int i = 0; i < array.size(); ++i) {
        atomicArray.set(i, array.getLong(i));
    }

    return (T) atomicArray;
}
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:18,代碼來源:AtomicLongArrayCodec.java

示例2: testCompareAndSetInMultipleThreads

import java.util.concurrent.atomic.AtomicLongArray; //導入方法依賴的package包/類
/**
 * compareAndSet in one thread enables another waiting for value
 * to succeed
 */
public void testCompareAndSetInMultipleThreads() throws InterruptedException {
    final AtomicLongArray a = new AtomicLongArray(1);
    a.set(0, 1);
    Thread t = new Thread(new CheckedRunnable() {
        public void realRun() {
            while (!a.compareAndSet(0, 2, 3))
                Thread.yield();
        }});

    t.start();
    assertTrue(a.compareAndSet(0, 1, 2));
    t.join(LONG_DELAY_MS);
    assertFalse(t.isAlive());
    assertEquals(3, a.get(0));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:AtomicLongArrayTest.java

示例3: testWeakCompareAndSet

import java.util.concurrent.atomic.AtomicLongArray; //導入方法依賴的package包/類
/**
 * repeated weakCompareAndSet succeeds in changing value when equal
 * to expected
 */
public void testWeakCompareAndSet() {
    AtomicLongArray aa = new AtomicLongArray(SIZE);
    for (int i = 0; i < SIZE; i++) {
        aa.set(i, 1);
        do {} while (!aa.weakCompareAndSet(i, 1, 2));
        do {} while (!aa.weakCompareAndSet(i, 2, -4));
        assertEquals(-4, aa.get(i));
        do {} while (!aa.weakCompareAndSet(i, -4, 7));
        assertEquals(7, aa.get(i));
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:16,代碼來源:AtomicLongArrayTest.java

示例4: testSerialization

import java.util.concurrent.atomic.AtomicLongArray; //導入方法依賴的package包/類
/**
 * a deserialized/reserialized array holds same values in same order
 */
public void testSerialization() throws Exception {
    AtomicLongArray x = new AtomicLongArray(SIZE);
    for (int i = 0; i < SIZE; i++)
        x.set(i, -i);
    AtomicLongArray y = serialClone(x);
    assertNotSame(x, y);
    assertEquals(x.length(), y.length());
    for (int i = 0; i < SIZE; i++) {
        assertEquals(x.get(i), y.get(i));
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:AtomicLongArrayTest.java

示例5: testGetAndAdd

import java.util.concurrent.atomic.AtomicLongArray; //導入方法依賴的package包/類
/**
 * getAndAdd returns previous value and adds given value
 */
public void testGetAndAdd() {
    AtomicLongArray aa = new AtomicLongArray(SIZE);
    for (int i = 0; i < SIZE; i++) {
        aa.set(i, 1);
        assertEquals(1, aa.getAndAdd(i, 2));
        assertEquals(3, aa.get(i));
        assertEquals(3, aa.getAndAdd(i, -4));
        assertEquals(-1, aa.get(i));
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:AtomicLongArrayTest.java

示例6: testLongArrayGetAndUpdate

import java.util.concurrent.atomic.AtomicLongArray; //導入方法依賴的package包/類
/**
 * AtomicLongArray getAndUpdate returns previous value and updates
 * result of supplied function
 */
public void testLongArrayGetAndUpdate() {
    AtomicLongArray a = new AtomicLongArray(1);
    a.set(0, 1);
    assertEquals(1L, a.getAndUpdate(0, Atomic8Test::addLong17));
    assertEquals(18L, a.getAndUpdate(0, Atomic8Test::addLong17));
    assertEquals(35L, a.get(0));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:12,代碼來源:Atomic8Test.java

示例7: testLongArrayUpdateAndGet

import java.util.concurrent.atomic.AtomicLongArray; //導入方法依賴的package包/類
/**
 * AtomicLongArray updateAndGet updates with supplied function and
 * returns result.
 */
public void testLongArrayUpdateAndGet() {
    AtomicLongArray a = new AtomicLongArray(1);
    a.set(0, 1);
    assertEquals(18L, a.updateAndGet(0, Atomic8Test::addLong17));
    assertEquals(35L, a.updateAndGet(0, Atomic8Test::addLong17));
    assertEquals(35L, a.get(0));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:12,代碼來源:Atomic8Test.java

示例8: testLongArrayGetAndAccumulate

import java.util.concurrent.atomic.AtomicLongArray; //導入方法依賴的package包/類
/**
 * AtomicLongArray getAndAccumulate returns previous value and updates
 * with supplied function.
 */
public void testLongArrayGetAndAccumulate() {
    AtomicLongArray a = new AtomicLongArray(1);
    a.set(0, 1);
    assertEquals(1L, a.getAndAccumulate(0, 2L, Long::sum));
    assertEquals(3L, a.getAndAccumulate(0, 3L, Long::sum));
    assertEquals(6L, a.get(0));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:12,代碼來源:Atomic8Test.java

示例9: testLongArrayAccumulateAndGet

import java.util.concurrent.atomic.AtomicLongArray; //導入方法依賴的package包/類
/**
 * AtomicLongArray accumulateAndGet updates with supplied function and
 * returns result.
 */
public void testLongArrayAccumulateAndGet() {
    AtomicLongArray a = new AtomicLongArray(1);
    a.set(0, 1);
    assertEquals(7L, a.accumulateAndGet(0, 6L, Long::sum));
    assertEquals(10L, a.accumulateAndGet(0, 3L, Long::sum));
    assertEquals(10L, a.get(0));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:12,代碼來源:Atomic8Test.java

示例10: testGetOpaqueSet

import java.util.concurrent.atomic.AtomicLongArray; //導入方法依賴的package包/類
/**
 * getOpaque returns the last value set
 */
public void testGetOpaqueSet() {
    AtomicLongArray aa = new AtomicLongArray(SIZE);
    for (int i = 0; i < SIZE; i++) {
        aa.set(i, 1);
        assertEquals(1, aa.getOpaque(i));
        aa.set(i, 2);
        assertEquals(2, aa.getOpaque(i));
        aa.set(i, -3);
        assertEquals(-3, aa.getOpaque(i));
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:AtomicLongArray9Test.java

示例11: testGetAcquireSet

import java.util.concurrent.atomic.AtomicLongArray; //導入方法依賴的package包/類
/**
 * getAcquire returns the last value set
 */
public void testGetAcquireSet() {
    AtomicLongArray aa = new AtomicLongArray(SIZE);
    for (int i = 0; i < SIZE; i++) {
        aa.set(i, 1);
        assertEquals(1, aa.getAcquire(i));
        aa.set(i, 2);
        assertEquals(2, aa.getAcquire(i));
        aa.set(i, -3);
        assertEquals(-3, aa.getAcquire(i));
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:AtomicLongArray9Test.java

示例12: testGetAndIncrement

import java.util.concurrent.atomic.AtomicLongArray; //導入方法依賴的package包/類
/**
 * getAndIncrement returns previous value and increments
 */
public void testGetAndIncrement() {
    AtomicLongArray aa = new AtomicLongArray(SIZE);
    for (int i = 0; i < SIZE; i++) {
        aa.set(i, 1);
        assertEquals(1, aa.getAndIncrement(i));
        assertEquals(2, aa.get(i));
        aa.set(i, -2);
        assertEquals(-2, aa.getAndIncrement(i));
        assertEquals(-1, aa.getAndIncrement(i));
        assertEquals(0, aa.getAndIncrement(i));
        assertEquals(1, aa.get(i));
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:AtomicLongArrayTest.java

示例13: testCompareAndExchangeAcquire

import java.util.concurrent.atomic.AtomicLongArray; //導入方法依賴的package包/類
/**
 * compareAndExchangeAcquire succeeds in changing value if equal to
 * expected else fails
 */
public void testCompareAndExchangeAcquire() {
    AtomicLongArray aa = new AtomicLongArray(SIZE);
    for (int i = 0; i < SIZE; i++) {
        aa.set(i, 1);
        assertEquals(1, aa.compareAndExchangeAcquire(i, 1, 2));
        assertEquals(2, aa.compareAndExchangeAcquire(i, 2, -4));
        assertEquals(-4, aa.get(i));
        assertEquals(-4, aa.compareAndExchangeAcquire(i,-5, 7));
        assertEquals(-4, aa.get(i));
        assertEquals(-4, aa.compareAndExchangeAcquire(i, -4, 7));
        assertEquals(7, aa.get(i));
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:AtomicLongArray9Test.java

示例14: testGetAndDecrement

import java.util.concurrent.atomic.AtomicLongArray; //導入方法依賴的package包/類
/**
 * getAndDecrement returns previous value and decrements
 */
public void testGetAndDecrement() {
    AtomicLongArray aa = new AtomicLongArray(SIZE);
    for (int i = 0; i < SIZE; i++) {
        aa.set(i, 1);
        assertEquals(1, aa.getAndDecrement(i));
        assertEquals(0, aa.getAndDecrement(i));
        assertEquals(-1, aa.getAndDecrement(i));
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:13,代碼來源:AtomicLongArrayTest.java

示例15: testWeakCompareAndSetPlain

import java.util.concurrent.atomic.AtomicLongArray; //導入方法依賴的package包/類
/**
 * repeated weakCompareAndSetPlain succeeds in changing value when equal
 * to expected
 */
public void testWeakCompareAndSetPlain() {
    AtomicLongArray aa = new AtomicLongArray(SIZE);
    for (int i = 0; i < SIZE; i++) {
        aa.set(i, 1);
        do {} while (!aa.weakCompareAndSetPlain(i, 1, 2));
        do {} while (!aa.weakCompareAndSetPlain(i, 2, -4));
        assertEquals(-4, aa.get(i));
        do {} while (!aa.weakCompareAndSetPlain(i, -4, 7));
        assertEquals(7, aa.get(i));
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:16,代碼來源:AtomicLongArray9Test.java


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