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


Java AtomicIntegerArray類代碼示例

本文整理匯總了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();
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:21,代碼來源:AtomicIntegerArrayCodec.java

示例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);
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:23,代碼來源:PartitionSenderOperator.java

示例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);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:9,代碼來源:Bug_7.java

示例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);
}
 
開發者ID:kefik,項目名稱:Pogamut3,代碼行數:16,代碼來源:AtomicIntegerList.java

示例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);
}
 
開發者ID:ozgurdemir,項目名稱:item-item-factorization,代碼行數:8,代碼來源:Accuracy.java

示例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) {}
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:11,代碼來源:AtomicIntegerArrayTest.java

示例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));
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:AtomicIntegerArrayTest.java

示例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));
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:AtomicIntegerArray9Test.java

示例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);
  }
}
 
開發者ID:arodchen,項目名稱:MaxSim,代碼行數:8,代碼來源:TestIntAtomicVolatile.java

示例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);
  }
}
 
開發者ID:arodchen,項目名稱:MaxSim,代碼行數:8,代碼來源:TestIntAtomicVolatile.java

示例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));
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:16,代碼來源:AtomicIntegerArray9Test.java

示例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));
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:13,代碼來源:AtomicIntegerArrayTest.java

示例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));
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:AtomicIntegerArrayTest.java

示例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));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:12,代碼來源:Atomic8Test.java

示例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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:Atomic8Test.java


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