java.util.concurrent.atomic.AtomicIntegerArray Java Examples

The following examples show how to use java.util.concurrent.atomic.AtomicIntegerArray. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AtomicIntegerArrayTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * a deserialized serialized array holds same values
 */
public void testSerialization() throws Exception {
    AtomicIntegerArray x = new AtomicIntegerArray(SIZE);
    for (int i = 0; i < SIZE; i++)
        x.set(i, -i);
    AtomicIntegerArray 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));
    }
}
 
Example #2
Source File: AtomicIntegerArrayTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * getAndDecrement returns previous value and decrements
 */
public void testGetAndDecrement() {
    AtomicIntegerArray aa = new AtomicIntegerArray(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));
    }
}
 
Example #3
Source File: AtomicIntegerArrayTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * 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));
    }
}
 
Example #4
Source File: PartitionSenderRootExec.java    From Bats with Apache License 2.0 5 votes vote down vote up
public PartitionSenderRootExec(RootFragmentContext context,
                               RecordBatch incoming,
                               HashPartitionSender operator,
                               boolean closeIncoming) throws OutOfMemoryException {
  super(context, context.newOperatorContext(operator, null), operator);
  this.incoming = incoming;
  this.operator = operator;
  this.closeIncoming = closeIncoming;
  this.context = context;
  outGoingBatchCount = operator.getDestinations().size();
  popConfig = operator;
  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 = operator.getChild().getCost().getOutputRowCount();
  final OptionManager optMgr = context.getOptions();
  long sliceTarget = optMgr.getOption(ExecConstants.SLICE_TARGET).num_val;
  int threadFactor = optMgr.getOption(PlannerSettings.PARTITION_SENDER_THREADS_FACTOR.getOptionName()).num_val.intValue();
  int tmpParts = 1;
  if ( sliceTarget != 0 && outGoingBatchCount != 0 ) {
    tmpParts = (int) Math.round((((cost / (sliceTarget*1.0)) / (outGoingBatchCount*1.0)) / (threadFactor*1.0)));
    if ( tmpParts < 1) {
      tmpParts = 1;
    }
  }
  final int imposedThreads = optMgr.getOption(PlannerSettings.PARTITION_SENDER_SET_THREADS.getOptionName()).num_val.intValue();
  if (imposedThreads > 0 ) {
    this.numberPartitions = imposedThreads;
  } else {
    this.numberPartitions = Math.min(tmpParts, optMgr.getOption(PlannerSettings.PARTITION_SENDER_MAX_THREADS.getOptionName()).num_val.intValue());
  }
  logger.info("Preliminary number of sending threads is: " + numberPartitions);
  this.actualPartitions = outGoingBatchCount > numberPartitions ? numberPartitions : outGoingBatchCount;
  this.stats.setLongStat(Metric.SENDING_THREADS_COUNT, actualPartitions);
  this.stats.setDoubleStat(Metric.COST, this.cost);
}
 
Example #5
Source File: Atomic60StatisticsImpl.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new statistics instance of the given type
 * 
 * @param type
 *          A description of the statistics
 * @param textId
 *          Text that identifies this statistic when it is monitored
 * @param numericId
 *          A number that displayed when this statistic is monitored
 * @param uniqueId
 *          A number that uniquely identifies this instance
 * @param system
 *          The distributed system that determines whether or not these
 *          statistics are stored (and collected) in GemFire shared memory or
 *          in the local VM
 */
public Atomic60StatisticsImpl(StatisticsType type, String textId,
    long numericId, long uniqueId, StatisticsManager system) {
  super(type, calcTextId(system, textId), calcNumericId(system, numericId),
      uniqueId, 0);
  this.dSystem = system;

  StatisticsTypeImpl realType = (StatisticsTypeImpl)type;
  int intCount = realType.getIntStatCount();
  int longCount = realType.getLongStatCount();
  int doubleCount = realType.getDoubleStatCount();

  if (intCount > 0) {
    this.intStorage = new AtomicIntegerArray(intCount);
  }
  else {
    this.intStorage = null;
  }

  if (longCount > 0) {
    this.longStorage = new AtomicLongArray(longCount);
  }
  else {
    this.longStorage = null;
  }

  if (doubleCount > 0) {
    this.doubleStorage = new AtomicLongArray(doubleCount);
  }
  else {
    this.doubleStorage = null;
  }
}
 
Example #6
Source File: Atomic8Test.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * 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));
}
 
Example #7
Source File: AtomicIntegerArray9Test.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * compareAndExchange succeeds in changing value if equal to
 * expected else fails
 */
public void testCompareAndExchange() {
    AtomicIntegerArray aa = new AtomicIntegerArray(SIZE);
    for (int i = 0; i < SIZE; i++) {
        aa.set(i, 1);
        assertEquals(1, aa.compareAndExchange(i, 1, 2));
        assertEquals(2, aa.compareAndExchange(i, 2, -4));
        assertEquals(-4, aa.get(i));
        assertEquals(-4, aa.compareAndExchange(i,-5, 7));
        assertEquals(-4, aa.get(i));
        assertEquals(-4, aa.compareAndExchange(i, -4, 7));
        assertEquals(7, aa.get(i));
    }
}
 
Example #8
Source File: Atomic8Test.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * AtomicIntegerArray getAndAccumulate returns previous value and updates
 * with supplied function.
 */
public void testIntArrayGetAndAccumulate() {
    AtomicIntegerArray a = new AtomicIntegerArray(1);
    a.set(0, 1);
    assertEquals(1, a.getAndAccumulate(0, 2, Integer::sum));
    assertEquals(3, a.getAndAccumulate(0, 3, Integer::sum));
    assertEquals(6, a.get(0));
}
 
Example #9
Source File: AtomicIntegerArrayDemo.java    From JavaCommon with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    System.out.println(31 - Integer.numberOfLeadingZeros(8));
    System.out.println(32 - Integer.numberOfLeadingZeros(8 - 1));
    int[] array = {1, 2, 3, 4};
    long[] longArray = {1, 2, 3, 4};
    AtomicIntegerArray atomicIntegerArray = new AtomicIntegerArray(array);
    atomicIntegerArray.getAndIncrement(1);

    AtomicLongArray atomicLongArray = new AtomicLongArray(longArray);
    atomicLongArray.getAndIncrement(1);

    Object[] objects = {new Object(), new Object()};
    AtomicReferenceArray atomicReferenceArray = new AtomicReferenceArray(objects);
    atomicReferenceArray.compareAndSet(1, new Object(), new Object());
}
 
Example #10
Source File: Atomic50StatisticsImpl.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public ThreadStorage(int intSize, int longSize) {
  this.owner = Thread.currentThread();
  if (intSize > 0) {
    this.intStore = new AtomicIntegerArray(intSize);
  } else {
    this.intStore = null;
  }
  if (longSize > 0) {
    this.longStore = new AtomicLongArray(longSize);
  } else {
    this.longStore = null;
  }
}
 
Example #11
Source File: AtomicIntegerArray9Test.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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));
    }
}
 
Example #12
Source File: TestIntAtomicVolatile.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
static void test_cp_oppos(AtomicIntegerArray a, AtomicIntegerArray b) {
  int limit = ARRLEN-1;
  for (int i = 0; i < ARRLEN; i+=1) {
    a.set(i, b.get(limit-i));
  }
}
 
Example #13
Source File: TestIntAtomicVolatile.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
static void test_cp_inv(AtomicIntegerArray a, AtomicIntegerArray b, int k) {
  for (int i = 0; i < ARRLEN-k; i+=1) {
    a.set((i+k), b.get(i+k));
  }
}
 
Example #14
Source File: TestIntAtomicVolatile.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
static void test_ci_inv(AtomicIntegerArray a, int k, int old) {
  for (int i = 0; i < ARRLEN-k; i+=1) {
    a.set((i+k),-123);
  }
}
 
Example #15
Source File: TestIntAtomicOrdered.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
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);
  }
}
 
Example #16
Source File: TestIntAtomicVolatile.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
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);
  }
}
 
Example #17
Source File: TestIntAtomicOrdered.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
static void test_cp_unalnsrc(AtomicIntegerArray a, AtomicIntegerArray b) {
  for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) {
    a.lazySet(i, b.get(i+UNALIGN_OFF));
  }
}
 
Example #18
Source File: Atomic50StatisticsImpl.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
private AtomicIntegerArray getThreadIntStorage() {
  return getThreadStorageForWrite().intStore;
}
 
Example #19
Source File: TestIntAtomicOrdered.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
static void test_2vi_off(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) {
  for (int i = 0; i < ARRLEN-OFFSET; i+=1) {
    a.lazySet((i+OFFSET), c);
    b.lazySet((i+OFFSET), d);
  }
}
 
Example #20
Source File: TestIntAtomicOrdered.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
static void test_cp_unalnsrc(AtomicIntegerArray a, AtomicIntegerArray b) {
  for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) {
    a.lazySet(i, b.get(i+UNALIGN_OFF));
  }
}
 
Example #21
Source File: TestIntAtomicOrdered.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
static void test_vi_off(AtomicIntegerArray a, int b, int old) {
  for (int i = 0; i < ARRLEN-OFFSET; i+=1) {
    a.lazySet((i+OFFSET), b);
  }
}
 
Example #22
Source File: TestIntAtomicOrdered.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
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);
  }
}
 
Example #23
Source File: TestIntAtomicVolatile.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
static void test_ci_off(AtomicIntegerArray a, int old) {
  for (int i = 0; i < ARRLEN-OFFSET; i+=1) {
    a.set((i+OFFSET), -123);
  }
}
 
Example #24
Source File: TestIntAtomicCAS.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
static void test_ci_neg(AtomicIntegerArray a, int old) {
  for (int i = ARRLEN-1; i >= 0; i-=1) {
    a.compareAndSet(i, old, -123);
  }
}
 
Example #25
Source File: TestIntAtomicOrdered.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
static void test_ci(AtomicIntegerArray a) {
  for (int i = 0; i < ARRLEN; i+=1) {
    a.lazySet(i, -123);
  }
}
 
Example #26
Source File: TestIntAtomicOrdered.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
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);
  }
}
 
Example #27
Source File: TestIntAtomicOrdered.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
static void test_cp_neg(AtomicIntegerArray a, AtomicIntegerArray b) {
  for (int i = ARRLEN-1; i >= 0; i-=1) {
    a.lazySet(i, b.get(i));
  }
}
 
Example #28
Source File: TestIntAtomicOrdered.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
static void test_ci_inv(AtomicIntegerArray a, int k, int old) {
  for (int i = 0; i < ARRLEN-k; i+=1) {
    a.lazySet((i+k),-123);
  }
}
 
Example #29
Source File: TestIntAtomicOrdered.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
static void test_ci_scl(AtomicIntegerArray a, int old) {
  for (int i = 0; i*SCALE < ARRLEN; i+=1) {
    a.lazySet((i*SCALE), -123);
  }
}
 
Example #30
Source File: TestIntAtomicCAS.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
static void test_2ci_unaln(AtomicIntegerArray a, AtomicIntegerArray b) {
  for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) {
    a.compareAndSet((i+UNALIGN_OFF), -1, -123);
    b.getAndSet(i, -103);
  }
}