本文整理匯總了Java中java.util.concurrent.atomic.AtomicIntegerArray類的典型用法代碼示例。如果您正苦於以下問題:Java AtomicIntegerArray類的具體用法?Java AtomicIntegerArray怎麽用?Java AtomicIntegerArray使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
AtomicIntegerArray類屬於java.util.concurrent.atomic包,在下文中一共展示了AtomicIntegerArray類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: write
import java.util.concurrent.atomic.AtomicIntegerArray; //導入依賴的package包/類
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType) throws IOException {
SerializeWriter out = serializer.getWriter();
if (object != null) {
AtomicIntegerArray array = (AtomicIntegerArray) object;
int len = array.length();
out.append('[');
for (int i = 0; i < len; i++) {
int val = array.get(i);
if (i != 0) {
out.write(',');
}
out.writeInt(val);
}
out.append(']');
} else if (out.isEnabled(SerializerFeature.WriteNullListAsEmpty)) {
out.write("[]");
} else {
out.writeNull();
}
}
示例2: PartitionSenderOperator
import java.util.concurrent.atomic.AtomicIntegerArray; //導入依賴的package包/類
public PartitionSenderOperator(
OperatorContext context,
TunnelProvider tunnelProvider,
HashPartitionSender config) {
super(config);
this.context = context;
this.tunnelProvider = tunnelProvider;
this.config = config;
this.stats = context.getStats();
outGoingBatchCount = config.getDestinations().size();
remainingReceivers = new AtomicIntegerArray(outGoingBatchCount);
remaingReceiverCount = new AtomicInteger(outGoingBatchCount);
stats.setLongStat(Metric.N_RECEIVERS, outGoingBatchCount);
// Algorithm to figure out number of threads to parallelize output
// numberOfRows/sliceTarget/numReceivers/threadfactor
this.cost = config.getChild().getCost();
this.numberPartitions = getNumberPartitions(context, config);
this.actualPartitions = outGoingBatchCount > numberPartitions ? numberPartitions : outGoingBatchCount;
this.stats.setLongStat(Metric.SENDING_THREADS_COUNT, actualPartitions);
this.stats.setDoubleStat(Metric.COST, this.cost);
logger.debug("Preliminary number of sending threads is: " + numberPartitions);
}
示例3: test_AtomicIntegerArray
import java.util.concurrent.atomic.AtomicIntegerArray; //導入依賴的package包/類
public void test_AtomicIntegerArray() throws Exception {
AtomicIntegerArray array = new AtomicIntegerArray(3);
array.set(0, 1);
array.set(1, 2);
array.set(2, 3);
String text = JSON.toJSONString(array);
Assert.assertEquals("[1,2,3]", text);
}
示例4: getArray
import java.util.concurrent.atomic.AtomicIntegerArray; //導入依賴的package包/類
private AtomicIntegerArray getArray(int index) {
int arrayIndex = arrayIndex(index);
if (size <= index) {
synchronized(arrays) {
if (size <= index) {
size = index + 1;
}
}
}
if (arrayIndex < arrays.size()) return arrays.get(arrayIndex);
synchronized(arrays) {
while (arrays.size() <= arrayIndex) arrays.add(new AtomicIntegerArray(capacityStep));
}
return arrays.get(arrayIndex);
}
示例5: Accuracy
import java.util.concurrent.atomic.AtomicIntegerArray; //導入依賴的package包/類
public Accuracy(int[] bins) {
this.bins = bins;
pos = new AtomicIntegerArray(bins.length);
posCorrect = new AtomicIntegerArray(bins.length);
neg = new AtomicIntegerArray(bins.length);
negCorrect = new AtomicIntegerArray(bins.length);
}
示例6: testConstructor2NPE
import java.util.concurrent.atomic.AtomicIntegerArray; //導入依賴的package包/類
/**
* constructor with null array throws NPE
*/
public void testConstructor2NPE() {
try {
int[] a = null;
new AtomicIntegerArray(a);
shouldThrow();
} catch (NullPointerException success) {}
}
示例7: testCompareAndSet
import java.util.concurrent.atomic.AtomicIntegerArray; //導入依賴的package包/類
/**
* compareAndSet succeeds in changing value if equal to expected else fails
*/
public void testCompareAndSet() {
AtomicIntegerArray aa = new AtomicIntegerArray(SIZE);
for (int i = 0; i < SIZE; i++) {
aa.set(i, 1);
assertTrue(aa.compareAndSet(i, 1, 2));
assertTrue(aa.compareAndSet(i, 2, -4));
assertEquals(-4, aa.get(i));
assertFalse(aa.compareAndSet(i, -5, 7));
assertEquals(-4, aa.get(i));
assertTrue(aa.compareAndSet(i, -4, 7));
assertEquals(7, aa.get(i));
}
}
示例8: testGetSetRelease
import java.util.concurrent.atomic.AtomicIntegerArray; //導入依賴的package包/類
/**
* get returns the last value setRelease
*/
public void testGetSetRelease() {
AtomicIntegerArray aa = new AtomicIntegerArray(SIZE);
for (int i = 0; i < SIZE; i++) {
aa.setRelease(i, 1);
assertEquals(1, aa.get(i));
aa.setRelease(i, 2);
assertEquals(2, aa.get(i));
aa.setRelease(i, -3);
assertEquals(-3, aa.get(i));
}
}
示例9: test_2ci_oppos
import java.util.concurrent.atomic.AtomicIntegerArray; //導入依賴的package包/類
static void test_2ci_oppos(AtomicIntegerArray a, AtomicIntegerArray b) {
int limit = ARRLEN-1;
for (int i = 0; i < ARRLEN; i+=1) {
a.set((limit-i), -123);
b.set(i, -103);
}
}
示例10: test_2vi_oppos
import java.util.concurrent.atomic.AtomicIntegerArray; //導入依賴的package包/類
static void test_2vi_oppos(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) {
int limit = ARRLEN-1;
for (int i = limit; i >= 0; i-=1) {
a.set(i, c);
b.set((limit-i), d);
}
}
示例11: testWeakCompareAndSetAcquire
import java.util.concurrent.atomic.AtomicIntegerArray; //導入依賴的package包/類
/**
* repeated weakCompareAndSetAcquire succeeds in changing value when equal
* to expected
*/
public void testWeakCompareAndSetAcquire() {
AtomicIntegerArray aa = new AtomicIntegerArray(SIZE);
for (int i = 0; i < SIZE; i++) {
aa.set(i, 1);
do {} while (!aa.weakCompareAndSetAcquire(i, 1, 2));
do {} while (!aa.weakCompareAndSetAcquire(i, 2, -4));
assertEquals(-4, aa.get(i));
do {} while (!aa.weakCompareAndSetAcquire(i, -4, 7));
assertEquals(7, aa.get(i));
}
}
示例12: testGetAndSet
import java.util.concurrent.atomic.AtomicIntegerArray; //導入依賴的package包/類
/**
* getAndSet returns previous value and sets to given value at given index
*/
public void testGetAndSet() {
AtomicIntegerArray aa = new AtomicIntegerArray(SIZE);
for (int i = 0; i < SIZE; i++) {
aa.set(i, 1);
assertEquals(1, aa.getAndSet(i, 0));
assertEquals(0, aa.getAndSet(i, -10));
assertEquals(-10, aa.getAndSet(i, 1));
}
}
示例13: testGetSet
import java.util.concurrent.atomic.AtomicIntegerArray; //導入依賴的package包/類
/**
* get returns the last value set at index
*/
public void testGetSet() {
AtomicIntegerArray aa = new AtomicIntegerArray(SIZE);
for (int i = 0; i < SIZE; i++) {
aa.set(i, 1);
assertEquals(1, aa.get(i));
aa.set(i, 2);
assertEquals(2, aa.get(i));
aa.set(i, -3);
assertEquals(-3, aa.get(i));
}
}
示例14: testIntArrayUpdateAndGet
import java.util.concurrent.atomic.AtomicIntegerArray; //導入依賴的package包/類
/**
* AtomicIntegerArray updateAndGet updates with supplied function and
* returns result.
*/
public void testIntArrayUpdateAndGet() {
AtomicIntegerArray a = new AtomicIntegerArray(1);
a.set(0, 1);
assertEquals(18, a.updateAndGet(0, Atomic8Test::addInt17));
assertEquals(35, a.updateAndGet(0, Atomic8Test::addInt17));
assertEquals(35, a.get(0));
}
示例15: testGetAndUpdateNPE
import java.util.concurrent.atomic.AtomicIntegerArray; //導入依賴的package包/類
/**
* All Atomic getAndUpdate methods throw NullPointerException on
* null function argument
*/
public void testGetAndUpdateNPE() {
Runnable[] throwingActions = {
() -> new AtomicLong().getAndUpdate(null),
() -> new AtomicInteger().getAndUpdate(null),
() -> new AtomicReference().getAndUpdate(null),
() -> new AtomicLongArray(1).getAndUpdate(0, null),
() -> new AtomicIntegerArray(1).getAndUpdate(0, null),
() -> new AtomicReferenceArray(1).getAndUpdate(0, null),
() -> aLongFieldUpdater().getAndUpdate(this, null),
() -> anIntFieldUpdater().getAndUpdate(this, null),
() -> anIntegerFieldUpdater().getAndUpdate(this, null),
};
assertThrows(NullPointerException.class, throwingActions);
}