当前位置: 首页>>代码示例>>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;未经允许,请勿转载。