本文整理汇总了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;
}
示例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));
}
示例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));
}
}
示例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));
}
}
示例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));
}
}
示例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));
}
示例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));
}
示例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));
}
示例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));
}
示例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));
}
}
示例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));
}
}
示例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));
}
}
示例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));
}
}
示例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));
}
}
示例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));
}
}