Java 类java.util.concurrent.atomic.AtomicIntegerArray 实例源码

项目:boohee_v5.6    文件:AtomicIntegerArrayCodec.java   
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();
    }
}
项目:dremio-oss    文件:PartitionSenderOperator.java   
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);
}
项目:GitHub    文件:Bug_7.java   
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);
}
项目:Pogamut3    文件:AtomicIntegerList.java   
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);
}
项目:item-item-factorization    文件:Accuracy.java   
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);
}
项目:openjdk-jdk10    文件:AtomicIntegerArrayTest.java   
/**
 * constructor with null array throws NPE
 */
public void testConstructor2NPE() {
    try {
        int[] a = null;
        new AtomicIntegerArray(a);
        shouldThrow();
    } catch (NullPointerException success) {}
}
项目:openjdk-jdk10    文件:AtomicIntegerArrayTest.java   
/**
 * 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));
    }
}
项目:openjdk-jdk10    文件:AtomicIntegerArray9Test.java   
/**
 * 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));
    }
}
项目:MaxSim    文件:TestIntAtomicVolatile.java   
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);
  }
}
项目:MaxSim    文件:TestIntAtomicVolatile.java   
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);
  }
}
项目:openjdk-jdk10    文件:AtomicIntegerArray9Test.java   
/**
 * 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));
    }
}
项目:openjdk-jdk10    文件:AtomicIntegerArrayTest.java   
/**
 * 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));
    }
}
项目:openjdk-jdk10    文件:AtomicIntegerArrayTest.java   
/**
 * 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));
    }
}
项目:openjdk-jdk10    文件:Atomic8Test.java   
/**
 * 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));
}
项目:openjdk-jdk10    文件:TestIntAtomicVolatile.java   
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);
  }
}
项目:openjdk-jdk10    文件:Atomic8Test.java   
/**
 * 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);
}
项目:openjdk-jdk10    文件:AtomicIntegerArray9Test.java   
/**
 * repeated weakCompareAndSetVolatile succeeds in changing value when equal
 * to expected
 */
public void testWeakCompareAndSetVolatile() {
    AtomicIntegerArray aa = new AtomicIntegerArray(SIZE);
    for (int i = 0; i < SIZE; i++) {
        aa.set(i, 1);
        do {} while (!aa.weakCompareAndSetVolatile(i, 1, 2));
        do {} while (!aa.weakCompareAndSetVolatile(i, 2, -4));
        assertEquals(-4, aa.get(i));
        do {} while (!aa.weakCompareAndSetVolatile(i, -4, 7));
        assertEquals(7, aa.get(i));
    }
}
项目:openjdk-jdk10    文件:Atomic8Test.java   
/**
 * All Atomic accumulateAndGet methods throw NullPointerException
 * on null function argument
 */
public void testAccumulateAndGetNPE() {
    Runnable[] throwingActions = {
        () -> new AtomicLong().accumulateAndGet(1L, null),
        () -> new AtomicInteger().accumulateAndGet(1, null),
        () -> new AtomicReference().accumulateAndGet(one, null),
        () -> new AtomicLongArray(1).accumulateAndGet(0, 1L, null),
        () -> new AtomicIntegerArray(1).accumulateAndGet(0, 1, null),
        () -> new AtomicReferenceArray(1).accumulateAndGet(0, one, null),
        () -> aLongFieldUpdater().accumulateAndGet(this, 1L, null),
        () -> anIntFieldUpdater().accumulateAndGet(this, 1, null),
        () -> anIntegerFieldUpdater().accumulateAndGet(this, one, null),
    };
    assertThrows(NullPointerException.class, throwingActions);
}
项目:openjdk-jdk10    文件:AtomicIntegerArray9Test.java   
/**
 * get returns the last value setPlain
 */
public void testGetSetPlain() {
    AtomicIntegerArray aa = new AtomicIntegerArray(SIZE);
    for (int i = 0; i < SIZE; i++) {
        aa.setPlain(i, 1);
        assertEquals(1, aa.get(i));
        aa.setPlain(i, 2);
        assertEquals(2, aa.get(i));
        aa.setPlain(i, -3);
        assertEquals(-3, aa.get(i));
    }
}
项目:openjdk-jdk10    文件:TestIntAtomicVolatile.java   
static void test_ci(AtomicIntegerArray a) {
  for (int i = 0; i < ARRLEN; i+=1) {
    a.set(i, -123);
  }
}
项目:MaxSim    文件:TestIntAtomicOrdered.java   
static void test_vi_oppos(AtomicIntegerArray a, int b, int old) {
  int limit = ARRLEN-1;
  for (int i = limit; i >= 0; i-=1) {
    a.lazySet((limit-i), b);
  }
}
项目:MaxSim    文件:TestIntAtomicOrdered.java   
static void test_2ci_unaln(AtomicIntegerArray a, AtomicIntegerArray b) {
  for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) {
    a.lazySet((i+UNALIGN_OFF), -123);
    b.lazySet(i, -103);
  }
}
项目:openjdk-jdk10    文件:TestIntAtomicOrdered.java   
static void test_ci_off(AtomicIntegerArray a, int old) {
  for (int i = 0; i < ARRLEN-OFFSET; i+=1) {
    a.lazySet((i+OFFSET), -123);
  }
}
项目:openjdk-jdk10    文件:TestIntAtomicCAS.java   
static void test_vi(AtomicIntegerArray a, int b, int old) {
  for (int i = 0; i < ARRLEN; i+=1) {
    a.compareAndSet(i, old, b);
  }
}
项目:ClusterDeviceControlPlatform    文件:DeviceStatusRepo.java   
private int getWorkStatus(int groupId, int deviceId) {
    AtomicIntegerArray array = WORK_STATUS_STORAGE.get(groupId);
    return array.get(deviceId);
}
项目:MaxSim    文件:TestIntAtomicOrdered.java   
static void test_vi_scl(AtomicIntegerArray a, int b, int old) {
  for (int i = 0; i*SCALE < ARRLEN; i+=1) {
    a.lazySet((i*SCALE), b);
  }
}
项目:MaxSim    文件:TestIntAtomicOrdered.java   
static void test_2vi(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) {
  for (int i = 0; i < ARRLEN; i+=1) {
    a.lazySet(i, c);
    b.lazySet(i, d);
  }
}
项目:MaxSim    文件:TestIntAtomicOrdered.java   
static void test_ci(AtomicIntegerArray a) {
  for (int i = 0; i < ARRLEN; i+=1) {
    a.lazySet(i, -123);
  }
}
项目:MaxSim    文件:TestIntAtomicOrdered.java   
static void test_vi(AtomicIntegerArray a, int b, int old) {
  for (int i = 0; i < ARRLEN; i+=1) {
    a.lazySet(i, b);
  }
}
项目:monarch    文件:IntegerStatsDeltaAggregator.java   
public IntegerStatsDeltaAggregator(List<String> keys) {
  this.keys = keys;
  prevCounters = new AtomicIntegerArray(keys.size());
  currCounters = new AtomicIntegerArray(keys.size());
  initializeArray(currCounters);
}
项目:openjdk-jdk10    文件:TestIntAtomicCAS.java   
static void test_2vi(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) {
  for (int i = 0; i < ARRLEN; i+=1) {
    a.compareAndSet(i, -123, c);
    b.compareAndSet(i, -103, d);
  }
}
项目:MaxSim    文件:TestIntAtomicOrdered.java   
static void test_2ci_off(AtomicIntegerArray a, AtomicIntegerArray b) {
  for (int i = 0; i < ARRLEN-OFFSET; i+=1) {
    a.lazySet((i+OFFSET), -123);
    b.lazySet((i+OFFSET), -103);
  }
}
项目:openjdk-jdk10    文件:TestIntAtomicOrdered.java   
static void test_ci_neg(AtomicIntegerArray a, int old) {
  for (int i = ARRLEN-1; i >= 0; i-=1) {
    a.lazySet(i,-123);
  }
}
项目:Java-9-Concurrency-Cookbook-Second-Edition    文件:Main.java   
/**
 * @param args
 */
public static void main(String[] args) {

    final int THREADS=100;
    /**
     * Atomic array whose elements will be incremented and decremented
     */
    AtomicIntegerArray vector=new AtomicIntegerArray(1000);
    /*
     * An incrementer task
     */
    Incrementer incrementer=new Incrementer(vector);
    /*
     * A decrementer task
     */
    Decrementer decrementer=new Decrementer(vector);

    /*
     * Create and execute 100 incrementer and 100 decrementer tasks
     */
    Thread threadIncrementer[]=new Thread[THREADS];
    Thread threadDecrementer[]=new Thread[THREADS];
    for (int i=0; i<THREADS; i++) {
        threadIncrementer[i]=new Thread(incrementer);
        threadDecrementer[i]=new Thread(decrementer);

        threadIncrementer[i].start();
        threadDecrementer[i].start();
    }

    /*
     * Wait for the finalization of all the tasks
     */
    for (int i=0; i<THREADS; i++) {
        try {
            threadIncrementer[i].join();
            threadDecrementer[i].join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    /*
     * Write the elements different from 0
     */
    int errors=0;
    for (int i=0; i<vector.length(); i++) {
        if (vector.get(i)!=0) {
            System.out.println("Vector["+i+"] : "+vector.get(i));
            errors++;
        }
    }

    if (errors==0) {
        System.out.printf("No errors found\n");
    }

    System.out.println("Main: End of the example");
}
项目:openjdk-jdk10    文件:TestIntAtomicVolatile.java   
static void test_2vi_neg(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) {
  for (int i = ARRLEN-1; i >= 0; i-=1) {
    a.set(i, c);
    b.set(i, d);
  }
}
项目:MaxSim    文件:TestIntAtomicVolatile.java   
static void test_vi(AtomicIntegerArray a, int b, int old) {
  for (int i = 0; i < ARRLEN; i+=1) {
    a.set(i, b);
  }
}
项目:openjdk-jdk10    文件:TestIntAtomicOrdered.java   
static void test_cp_unalndst(AtomicIntegerArray a, AtomicIntegerArray b) {
  for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) {
    a.lazySet((i+UNALIGN_OFF), b.get(i));
  }
}
项目:openjdk-jdk10    文件:TestIntAtomicCAS.java   
static void test_cp_unalnsrc(AtomicIntegerArray a, AtomicIntegerArray b) {
  for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) {
    a.getAndSet(i, b.get(i+UNALIGN_OFF));
  }
}
项目:openjdk-jdk10    文件:TestIntAtomicCAS.java   
static void test_2ci_aln(AtomicIntegerArray a, AtomicIntegerArray b) {
  for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) {
    a.compareAndSet((i+ALIGN_OFF), -1, -123);
    b.getAndSet(i, -103);
  }
}
项目:MaxSim    文件:TestIntAtomicVolatile.java   
static void test_ci_neg(AtomicIntegerArray a, int old) {
  for (int i = ARRLEN-1; i >= 0; i-=1) {
    a.set(i,-123);
  }
}