本文整理汇总了Java中java.util.concurrent.atomic.AtomicLong.getAndIncrement方法的典型用法代码示例。如果您正苦于以下问题:Java AtomicLong.getAndIncrement方法的具体用法?Java AtomicLong.getAndIncrement怎么用?Java AtomicLong.getAndIncrement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.atomic.AtomicLong
的用法示例。
在下文中一共展示了AtomicLong.getAndIncrement方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendMessageToKafka
import java.util.concurrent.atomic.AtomicLong; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private void sendMessageToKafka(String key, DbusMessage dbusMessage, AtomicLong sendCnt, AtomicLong recvCnt, AtomicBoolean isError) throws Exception{
if(stringProducer == null) {
throw new Exception("producer is null, can't send to kafka!");
}
ProducerRecord record = new ProducerRecord<>(resultTopic, key, dbusMessage.toString());
sendCnt.getAndIncrement();
stringProducer.send(record, new Callback() {
public void onCompletion(RecordMetadata metadata, Exception e) {
if (e != null) {
e.printStackTrace();
isError.set(true);
}else{
recvCnt.getAndIncrement();
}
}
});
}
示例2: postCompleteWithRequest
import java.util.concurrent.atomic.AtomicLong; //导入方法依赖的package包/类
@Test
public void postCompleteWithRequest() {
TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
ArrayDeque<Integer> queue = new ArrayDeque<Integer>();
AtomicLong state = new AtomicLong();
BooleanSupplier isCancelled = new BooleanSupplier() {
@Override
public boolean getAsBoolean() throws Exception {
return false;
}
};
ts.onSubscribe(new BooleanSubscription());
queue.offer(1);
state.getAndIncrement();
QueueDrainHelper.postComplete(ts, queue, state, isCancelled);
ts.assertResult(1);
}
示例3: postCompleteCancelled
import java.util.concurrent.atomic.AtomicLong; //导入方法依赖的package包/类
@Test
public void postCompleteCancelled() {
final TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
ArrayDeque<Integer> queue = new ArrayDeque<Integer>();
AtomicLong state = new AtomicLong();
BooleanSupplier isCancelled = new BooleanSupplier() {
@Override
public boolean getAsBoolean() throws Exception {
return ts.isCancelled();
}
};
ts.onSubscribe(new BooleanSubscription());
queue.offer(1);
state.getAndIncrement();
ts.cancel();
QueueDrainHelper.postComplete(ts, queue, state, isCancelled);
ts.assertEmpty();
}
示例4: postCompleteCancelledAfterOne
import java.util.concurrent.atomic.AtomicLong; //导入方法依赖的package包/类
@Test
public void postCompleteCancelledAfterOne() {
final TestSubscriber<Integer> ts = new TestSubscriber<Integer>() {
@Override
public void onNext(Integer t) {
super.onNext(t);
cancel();
}
};
ArrayDeque<Integer> queue = new ArrayDeque<Integer>();
AtomicLong state = new AtomicLong();
BooleanSupplier isCancelled = new BooleanSupplier() {
@Override
public boolean getAsBoolean() throws Exception {
return ts.isCancelled();
}
};
ts.onSubscribe(new BooleanSubscription());
queue.offer(1);
state.getAndIncrement();
QueueDrainHelper.postComplete(ts, queue, state, isCancelled);
ts.assertValue(1).assertNoErrors().assertNotComplete();
}
示例5: tick
import java.util.concurrent.atomic.AtomicLong; //导入方法依赖的package包/类
void tick() {
AtomicLong localCounter = this.counter;
if (localCounter.getAndIncrement() == 0) {
int emitted = 0;
do {
if (this.requested.get() > 0) {
Object o = this.buffer.poll();
if (o != null) {
if (this.buffer.isCompleted(o)) {
this.child.onCompleted();
} else {
this.buffer.accept(o, this.child);
emitted++;
this.requested.decrementAndGet();
}
}
}
} while (localCounter.decrementAndGet() > 0);
if (emitted > 0) {
for (MultiSourceRequestableSubscriber<T, R> s : this.subscribers) {
s.requestUpTo((long) emitted);
}
}
}
}
示例6: getNextSeqNo
import java.util.concurrent.atomic.AtomicLong; //导入方法依赖的package包/类
/**
* Get the next sequence number for the specified path that includes: table-name, partition/bucket
* id, time-partition-id
*
* @param path the unique path against which the sequence id is maintained
* @return the next available sequence id
*/
protected long getNextSeqNo(final String path) {
synchronized (bucketSeqNoMap) {
AtomicLong mapValue = bucketSeqNoMap.get(path);
if (mapValue != null) {
return mapValue.getAndIncrement();
}
bucketSeqNoMap.put(path, new AtomicLong(1));
return 0;
}
}
示例7: getNextSeqNo
import java.util.concurrent.atomic.AtomicLong; //导入方法依赖的package包/类
/**
* Get the next sequence number for the specified path that includes: table-name, partition/bucket
* id, time-partition-id
*
* @param path the unique path against which the sequence id is maintained
* @return the next available sequence id
*/
public long getNextSeqNo(final String path) {
synchronized (bucketSeqNoMap) {
AtomicLong mapValue = bucketSeqNoMap.get(path);
if (mapValue != null) {
return mapValue.getAndIncrement();
}
bucketSeqNoMap.put(path, new AtomicLong(1));
return 0;
}
}
示例8: getNextSeqNo
import java.util.concurrent.atomic.AtomicLong; //导入方法依赖的package包/类
/**
* Get next sequence number
*
* @return next sequence number.
*/
public long getNextSeqNo(String tableName, int partitionId) {
synchronized (bucketSeqNoMap) {
AtomicLong mapValue = bucketSeqNoMap.get(tableName + "_" + partitionId);
if (mapValue != null) {
return mapValue.getAndIncrement();
}
bucketSeqNoMap.put(tableName + "_" + partitionId, new AtomicLong(1));
return 0;
}
}
示例9: run
import java.util.concurrent.atomic.AtomicLong; //导入方法依赖的package包/类
public void run() {
phaser.arriveAndAwaitAdvance();
phaser.arriveAndAwaitAdvance();
AtomicLong a = adder;
for (int i = 0; i < incs; ++i)
a.getAndIncrement();
result = a.get();
phaser.arrive();
}