當前位置: 首頁>>代碼示例>>Java>>正文


Java AtomicLong.getAndIncrement方法代碼示例

本文整理匯總了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();
            }
        }
    });
}
 
開發者ID:BriData,項目名稱:DBus,代碼行數:20,代碼來源:PagedBatchDataFetchingBolt.java

示例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);
}
 
開發者ID:akarnokd,項目名稱:RxJava3-preview,代碼行數:21,代碼來源:QueueDrainHelperTest.java

示例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();
}
 
開發者ID:akarnokd,項目名稱:RxJava3-preview,代碼行數:22,代碼來源:QueueDrainHelperTest.java

示例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();
}
 
開發者ID:akarnokd,項目名稱:RxJava3-preview,代碼行數:27,代碼來源:QueueDrainHelperTest.java

示例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);
            }
        }
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:26,代碼來源:OnSubscribeCombineLatest.java

示例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;
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:18,代碼來源:AbstractTierStoreWriter.java

示例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;
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:18,代碼來源:ORCExternalStoreWriter.java

示例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;
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:16,代碼來源:WriteAheadLog.java

示例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();
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:10,代碼來源:LongAdderDemo.java


注:本文中的java.util.concurrent.atomic.AtomicLong.getAndIncrement方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。