use of java.util.concurrent.atomic.AtomicIntegerArray in project neo4j by neo4j.
the class ForkedProcessorStepTest method shouldKeepForkedOrderIntactWhenChangingProcessorCount.
@Test
void shouldKeepForkedOrderIntactWhenChangingProcessorCount() throws Exception {
int length = 100;
AtomicIntegerArray reference = new AtomicIntegerArray(length);
// GIVEN
StageControl control = new SimpleStageControl();
int availableProcessors = Runtime.getRuntime().availableProcessors();
ForkedProcessorStep<int[]> step = new ForkedProcessorStep<>(control, "Processor", config(availableProcessors)) {
@Override
protected void forkedProcess(int id, int processors, int[] batch) throws InterruptedException {
int ticket = batch[0];
Thread.sleep(ThreadLocalRandom.current().nextInt(10));
for (int i = 1; i < batch.length; i++) {
if (batch[i] % processors == id) {
boolean compareAndSet = reference.compareAndSet(batch[i], ticket, ticket + 1);
assertTrue(compareAndSet, "I am " + id + ". Was expecting " + ticket + " for " + batch[i] + " but was " + reference.get(batch[i]));
}
}
}
};
DeadEndStep downstream = new DeadEndStep(control);
step.setDownstream(downstream);
// WHEN
step.start(0);
downstream.start(0);
ThreadLocalRandom random = ThreadLocalRandom.current();
for (int ticket = 0; ticket < 200; ticket++) {
// a particular batch.
if (random.nextFloat() < 0.1) {
step.processors(random.nextInt(-2, 4));
}
int[] batch = new int[length];
batch[0] = ticket;
for (int j = 1; j < batch.length; j++) {
batch[j] = j - 1;
}
step.receive(ticket, batch);
}
step.endOfUpstream();
step.awaitCompleted();
step.close();
downstream.close();
}
use of java.util.concurrent.atomic.AtomicIntegerArray in project neo4j-apoc-procedures by neo4j-contrib.
the class PageRankArrayStorageParallelCypher method compute.
public void compute(int iterations, int[] sourceDegreeData, int[] sourceChunkStartingIndex, int[] relationshipTarget, int[] relationshipWeight) {
previousPageRanks = new int[nodeCount];
pageRanksAtomic = new AtomicIntegerArray(nodeCount);
stats.iterations = iterations;
long before = System.currentTimeMillis();
for (int iteration = 0; iteration < iterations; iteration++) {
long beforeIteration = System.currentTimeMillis();
startIteration(sourceChunkStartingIndex, sourceDegreeData, relationshipWeight);
iterateParallel(iteration, sourceDegreeData, sourceChunkStartingIndex, relationshipTarget, relationshipWeight);
long afterIteration = System.currentTimeMillis();
log.info("Time for iteration " + iteration + " " + (afterIteration - beforeIteration) + " millis");
}
long after = System.currentTimeMillis();
stats.computeMillis = (after - before);
}
use of java.util.concurrent.atomic.AtomicIntegerArray in project fastjson by alibaba.
the class AtomicCodec method write.
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
SerializeWriter out = serializer.out;
if (object instanceof AtomicInteger) {
AtomicInteger val = (AtomicInteger) object;
out.writeInt(val.get());
return;
}
if (object instanceof AtomicLong) {
AtomicLong val = (AtomicLong) object;
out.writeLong(val.get());
return;
}
if (object instanceof AtomicBoolean) {
AtomicBoolean val = (AtomicBoolean) object;
out.append(val.get() ? "true" : "false");
return;
}
if (object == null) {
out.writeNull(SerializerFeature.WriteNullListAsEmpty);
return;
}
if (object instanceof AtomicIntegerArray) {
AtomicIntegerArray array = (AtomicIntegerArray) object;
int len = array.length();
out.write('[');
for (int i = 0; i < len; ++i) {
int val = array.get(i);
if (i != 0) {
out.write(',');
}
out.writeInt(val);
}
out.write(']');
return;
}
AtomicLongArray array = (AtomicLongArray) object;
int len = array.length();
out.write('[');
for (int i = 0; i < len; ++i) {
long val = array.get(i);
if (i != 0) {
out.write(',');
}
out.writeLong(val);
}
out.write(']');
}
use of java.util.concurrent.atomic.AtomicIntegerArray in project fastjson by alibaba.
the class Bug_7 method test_AtomicIntegerArray.
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);
}
use of java.util.concurrent.atomic.AtomicIntegerArray in project hazelcast by hazelcast.
the class PostponedSnapshotTestBase method setup.
@Before
public void setup() {
instance = createHazelcastInstance();
latches = new AtomicIntegerArray(2);
}
Aggregations