当前位置: 首页>>代码示例>>Java>>正文


Java AtomicLong.addAndGet方法代码示例

本文整理汇总了Java中java.util.concurrent.atomic.AtomicLong.addAndGet方法的典型用法代码示例。如果您正苦于以下问题:Java AtomicLong.addAndGet方法的具体用法?Java AtomicLong.addAndGet怎么用?Java AtomicLong.addAndGet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.atomic.AtomicLong的用法示例。


在下文中一共展示了AtomicLong.addAndGet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: gatherAllCopyResults

import java.util.concurrent.atomic.AtomicLong; //导入方法依赖的package包/类
private Metrics gatherAllCopyResults() {
  AtomicLong bytesReplicated = new AtomicLong(0);
  registerRunningMetrics(bytesReplicated);
  for (Copy copyJob : copyJobs) {
    try {
      copyJob.waitForCompletion();
      long alreadyReplicated = bytesReplicated.addAndGet(copyJob.getProgress().getTotalBytesToTransfer());
      if (totalBytesToReplicate > 0) {
        LOG.info("Replicating...': {}% complete",
            String.format("%.0f", (alreadyReplicated / (double) totalBytesToReplicate) * 100.0));
      }
    } catch (InterruptedException e) {
      throw new CircusTrainException(e);
    }
  }
  ImmutableMap<String, Long> metrics = ImmutableMap.of(S3S3CopierMetrics.Metrics.TOTAL_BYTES_TO_REPLICATE.name(),
      totalBytesToReplicate);
  return new S3S3CopierMetrics(metrics, bytesReplicated.get());
}
 
开发者ID:HotelsDotCom,项目名称:circus-train,代码行数:20,代码来源:S3S3Copier.java

示例2: doPut

import java.util.concurrent.atomic.AtomicLong; //导入方法依赖的package包/类
private void doPut(String tableName, final List<com.alicloud.tablestore.adaptor.struct.OPut> puts) throws IOException {
  ArrayList<com.alicloud.tablestore.adaptor.struct.OPut> tableWriteBuffer = getTableWriteBuffer(tableName);
  AtomicLong currentBufferSize = getTableCurrentBufferSize(tableName);
  boolean autoFlush = getAutoFlush(tableName);
  long writeBufferSize = getWriteBufferSize(tableName);

  List<com.alicloud.tablestore.adaptor.struct.OPut> flushPuts = null;
  synchronized (tableWriteBuffer) {
    for (com.alicloud.tablestore.adaptor.struct.OPut put : puts) {
      tableWriteBuffer.add(put);
      currentBufferSize.addAndGet(put.getWritableSize());
    }
    if (autoFlush || currentBufferSize.get() > writeBufferSize) {
      flushPuts = new ArrayList<com.alicloud.tablestore.adaptor.struct.OPut>(tableWriteBuffer);
      tableWriteBuffer.clear();
      currentBufferSize.set(0);
    }
  }
  if (flushPuts != null && !flushPuts.isEmpty()) {
    doCommits(tableName, flushPuts);
  }
}
 
开发者ID:aliyun,项目名称:aliyun-tablestore-hbase-client,代码行数:23,代码来源:OTSAdapter.java

示例3: doCommits

import java.util.concurrent.atomic.AtomicLong; //导入方法依赖的package包/类
private void doCommits(String tableName, final List<com.alicloud.tablestore.adaptor.struct.OPut> puts) throws IOException {
  boolean flushSuccessfully = false;
  try {
    otsProxy.putMultiple(tableName, puts);
    flushSuccessfully = true;
  } finally {
    if (!flushSuccessfully && !getClearBufferOnFail(tableName)) {
      ArrayList<com.alicloud.tablestore.adaptor.struct.OPut> tableWriteBuffer = getTableWriteBuffer(tableName);
      synchronized (tableWriteBuffer) {
        AtomicLong currentBufferSize = getTableCurrentBufferSize(tableName);
        for (com.alicloud.tablestore.adaptor.struct.OPut put : puts) {
          tableWriteBuffer.add(put);
          currentBufferSize.addAndGet(put.getWritableSize());
        }
      }
    }
  }
}
 
开发者ID:aliyun,项目名称:aliyun-tablestore-hbase-client,代码行数:19,代码来源:OTSAdapter.java

示例4: updateCounter

import java.util.concurrent.atomic.AtomicLong; //导入方法依赖的package包/类
/**
 * Increment the counter
 * @param counterName counter name
 * @param updateValue increment value
 */
public void updateCounter(String counterName, int updateValue) {
  AtomicLong counter = metrics.get(counterName);
  if(counter == null) {
    counter = metrics.putIfAbsent(counterName, new AtomicLong(0));
    if(counter == null) {
      counter = metrics.get(counterName);
    }
  }
  counter.addAndGet(updateValue);
}
 
开发者ID:Tencent,项目名称:angel,代码行数:16,代码来源:TaskContext.java

示例5: generateTableData

import java.util.concurrent.atomic.AtomicLong; //导入方法依赖的package包/类
/**
 * Load the tuples for the given table name
 * @param tableName
 */
protected void generateTableData(String tableName) {
    LOG.debug("Starting data generator for '" + tableName + "'");
    final AbstractTableGenerator generator = this.generators.get(tableName);
    assert(generator != null);
    long tableSize = generator.getTableSize();
    long batchSize = generator.getBatchSize();
    final AtomicLong table_ctr = this.table_sizes.get(tableName); 
    VoltTable table = generator.getVoltTable();
    
    LOG.info("Loading " + tableSize + " tuples for table '" + tableName + "'");
    while (generator.hasMore()) {
        generator.addRow();
        if (table.getRowCount() >= batchSize) {
            if (table_ctr.get() % 100000 == 0) LOG.info(String.format(tableName + ": loading %d rows (id %d of %d)", table.getRowCount(), generator.getCount(), tableSize));
            loadVoltTable(tableName, table);
            table_ctr.addAndGet(table.getRowCount());
            table.clearRowData();
        }
    } // WHILE
    if (table.getRowCount() > 0) {
        LOG.info(tableName + ": loading final " + table.getRowCount() + " rows.");
        loadVoltTable(tableName, table);
        this.table_sizes.get(tableName).addAndGet(table.getRowCount());
        table.clearRowData();
    }
    LOG.info(tableName + ": Inserted " + this.table_sizes.get(tableName) + " tuples");
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:32,代码来源:MapReduceLoader.java

示例6: testConcurrentDeleteByQueriesOnSameDocs

import java.util.concurrent.atomic.AtomicLong; //导入方法依赖的package包/类
public void testConcurrentDeleteByQueriesOnSameDocs() throws Throwable {
    final long docs = randomIntBetween(50, 100);

    List<IndexRequestBuilder> builders = new ArrayList<>();
    for (int i = 0; i < docs; i++) {
        builders.add(client().prepareIndex("test", "doc", String.valueOf(i)).setSource("foo", "bar"));
    }
    indexRandom(true, true, true, builders);

    final Thread[] threads =  new Thread[scaledRandomIntBetween(2, 9)];

    final CountDownLatch start = new CountDownLatch(1);
    final MatchQueryBuilder query = matchQuery("foo", "bar");
    final AtomicLong deleted = new AtomicLong(0);

    for (int t = 0; t < threads.length; t++) {
        Runnable r = () -> {
            try {
                start.await();

                BulkByScrollResponse response = deleteByQuery().source("test").filter(query).refresh(true).get();
                // Some deletions might fail due to version conflict, but
                // what matters here is the total of successful deletions
                deleted.addAndGet(response.getDeleted());
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        };
        threads[t] = new Thread(r);
        threads[t].start();
    }

    start.countDown();
    for (Thread thread : threads) {
        thread.join();
    }

    assertHitCount(client().prepareSearch("test").setSize(0).get(), 0L);
    assertThat(deleted.get(), equalTo(docs));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:41,代码来源:DeleteByQueryConcurrentTests.java

示例7: testGetAgeInMillis

import java.util.concurrent.atomic.AtomicLong; //导入方法依赖的package包/类
public void testGetAgeInMillis() throws Exception {
    AtomicLong time = new AtomicLong();

    PrioritizedRunnable runnable = new PrioritizedRunnable(Priority.NORMAL, time::get) {
        @Override
        public void run() {
        }
    };
    assertEquals(0, runnable.getAgeInMillis());
    int milliseconds = randomIntBetween(1, 256);
    time.addAndGet(TimeUnit.NANOSECONDS.convert(milliseconds, TimeUnit.MILLISECONDS));
    assertEquals(milliseconds, runnable.getAgeInMillis());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:PrioritizedRunnableTests.java

示例8: merge

import java.util.concurrent.atomic.AtomicLong; //导入方法依赖的package包/类
public void merge(CountCollector other){
	for(Map.Entry<String,AtomicLong> otherEntry : MapTool.nullSafe(other.getCountByKey()).entrySet()){
		AtomicLong existingValue = countByKey.get(otherEntry.getKey());
		if(existingValue != null){
			existingValue.addAndGet(otherEntry.getValue().longValue());
		}else{
			countByKey.put(otherEntry.getKey(), new AtomicLong(otherEntry.getValue().longValue()));
		}
	}
}
 
开发者ID:hotpads,项目名称:datarouter,代码行数:11,代码来源:AtomicCounter.java

示例9: pollQueue

import java.util.concurrent.atomic.AtomicLong; //导入方法依赖的package包/类
void pollQueue() {
    int emitted = 0;
    AtomicLong localRequested = this.requested;
    AtomicLong localCounter = this.counter;
    do {
        localCounter.set(1);
        long produced = 0;
        long r = localRequested.get();
        while (!this.child.isUnsubscribed()) {
            if (this.finished) {
                Throwable error = this.error;
                if (error != null) {
                    this.queue.clear();
                    this.child.onError(error);
                    return;
                } else if (this.queue.isEmpty()) {
                    this.child.onCompleted();
                    return;
                }
            }
            if (r > 0) {
                Object o = this.queue.poll();
                if (o != null) {
                    this.child.onNext(this.on.getValue(o));
                    r--;
                    emitted++;
                    produced++;
                }
            }
            if (produced > 0 && localRequested.get() != Long.MAX_VALUE) {
                localRequested.addAndGet(-produced);
            }
        }
        return;
    } while (localCounter.decrementAndGet() > 0);
    if (emitted > 0) {
        request((long) emitted);
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:40,代码来源:OperatorObserveOn.java

示例10: addToCounter

import java.util.concurrent.atomic.AtomicLong; //导入方法依赖的package包/类
/**
 * @param counterName
 * @param delta
 */
public void addToCounter(String counterName, long delta) {
  AtomicLong c = this.counters.get(counterName);
  if (c != null) {
    c.addAndGet(delta);
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:11,代码来源:ServerSideScanMetrics.java

示例11: postCompleteDrain

import java.util.concurrent.atomic.AtomicLong; //导入方法依赖的package包/类
/**
     * Drains the queue based on the outstanding requests in post-completed mode (only!).
     *
     * @param n the current request amount
     * @param actual the target Subscriber to send events to
     * @param queue the queue to drain if in the post-complete state
     * @param state holds the request amount and the post-completed flag
     * @param isCancelled a supplier that returns true if the drain has been cancelled
     * @return true if the queue was completely drained or the drain process was cancelled
     */
    static <T> boolean postCompleteDrain(long n,
                                         Subscriber<? super T> actual,
                                         Queue<T> queue,
                                         AtomicLong state,
                                         BooleanSupplier isCancelled) {

// TODO enable fast-path
//        if (n == -1 || n == Long.MAX_VALUE) {
//            for (;;) {
//                if (isCancelled.getAsBoolean()) {
//                    break;
//                }
//
//                T v = queue.poll();
//
//                if (v == null) {
//                    actual.onComplete();
//                    break;
//                }
//
//                actual.onNext(v);
//            }
//
//            return true;
//        }

        long e = n & COMPLETED_MASK;

        for (; ; ) {

            while (e != n) {
                if (isCancelled(isCancelled)) {
                    return true;
                }

                T t = queue.poll();

                if (t == null) {
                    actual.onComplete();
                    return true;
                }

                actual.onNext(t);
                e++;
            }

            if (isCancelled(isCancelled)) {
                return true;
            }

            if (queue.isEmpty()) {
                actual.onComplete();
                return true;
            }

            n = state.get();

            if (n == e) {

                n = state.addAndGet(-(e & REQUESTED_MASK));

                if ((n & REQUESTED_MASK) == 0L) {
                    return false;
                }

                e = n & COMPLETED_MASK;
            }
        }

    }
 
开发者ID:akarnokd,项目名称:RxJava3-preview,代码行数:81,代码来源:QueueDrainHelper.java

示例12: emitLoop

import java.util.concurrent.atomic.AtomicLong; //导入方法依赖的package包/类
void emitLoop() {
    Subscriber<? super R> child = this.child;
    Queue<Object> queue = this.queue;
    NotificationLite<R> nl = NotificationLite.instance();
    AtomicLong requested = this.requested;
    long r = requested.get();
    while (true) {
        boolean max = r == Long.MAX_VALUE;
        if (!checkTerminated(this.done, queue.isEmpty(), child)) {
            long e = 0;
            while (r != 0) {
                boolean d = this.done;
                Object o = queue.poll();
                boolean empty = o == null;
                if (!checkTerminated(d, empty, child)) {
                    if (empty) {
                        break;
                    }
                    R v = nl.getValue(o);
                    try {
                        child.onNext(v);
                        r--;
                        e--;
                    } catch (Throwable ex) {
                        Exceptions.throwIfFatal(ex);
                        child.onError(OnErrorThrowable.addValueAsLastCause(ex, v));
                        return;
                    }
                }
                return;
            }
            if (!(e == 0 || max)) {
                r = requested.addAndGet(e);
            }
            synchronized (this) {
                if (this.missed) {
                    this.missed = false;
                } else {
                    this.emitting = false;
                    return;
                }
            }
        }
        return;
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:47,代码来源:OperatorScan.java

示例13: incr

import java.util.concurrent.atomic.AtomicLong; //导入方法依赖的package包/类
@Override
public void incr(String group, String name, long count) {
  AtomicLong counter = getToAdd(group, name, AtomicLong.class, counterLock, counters);
  counter.addAndGet(count);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:6,代码来源:InstrumentationService.java

示例14: BucketAllocator

import java.util.concurrent.atomic.AtomicLong; //导入方法依赖的package包/类
/**
 * Rebuild the allocator's data structures from a persisted map.
 * @param availableSpace capacity of cache
 * @param map A map stores the block key and BucketEntry(block's meta data
 *          like offset, length)
 * @param realCacheSize cached data size statistics for bucket cache
 * @throws BucketAllocatorException
 */
BucketAllocator(long availableSpace, int[] bucketSizes, Map<BlockCacheKey, BucketEntry> map,
    AtomicLong realCacheSize) throws BucketAllocatorException {
  this(availableSpace, bucketSizes);

  // each bucket has an offset, sizeindex. probably the buckets are too big
  // in our default state. so what we do is reconfigure them according to what
  // we've found. we can only reconfigure each bucket once; if more than once,
  // we know there's a bug, so we just log the info, throw, and start again...
  boolean[] reconfigured = new boolean[buckets.length];
  for (Map.Entry<BlockCacheKey, BucketEntry> entry : map.entrySet()) {
    long foundOffset = entry.getValue().offset();
    int foundLen = entry.getValue().getLength();
    int bucketSizeIndex = -1;
    for (int i = 0; i < bucketSizes.length; ++i) {
      if (foundLen <= bucketSizes[i]) {
        bucketSizeIndex = i;
        break;
      }
    }
    if (bucketSizeIndex == -1) {
      throw new BucketAllocatorException(
          "Can't match bucket size for the block with size " + foundLen);
    }
    int bucketNo = (int) (foundOffset / bucketCapacity);
    if (bucketNo < 0 || bucketNo >= buckets.length)
      throw new BucketAllocatorException("Can't find bucket " + bucketNo
          + ", total buckets=" + buckets.length
          + "; did you shrink the cache?");
    Bucket b = buckets[bucketNo];
    if (reconfigured[bucketNo]) {
      if (b.sizeIndex() != bucketSizeIndex)
        throw new BucketAllocatorException(
            "Inconsistent allocation in bucket map;");
    } else {
      if (!b.isCompletelyFree())
        throw new BucketAllocatorException("Reconfiguring bucket "
            + bucketNo + " but it's already allocated; corrupt data");
      // Need to remove the bucket from whichever list it's currently in at
      // the moment...
      BucketSizeInfo bsi = bucketSizeInfos[bucketSizeIndex];
      BucketSizeInfo oldbsi = bucketSizeInfos[b.sizeIndex()];
      oldbsi.removeBucket(b);
      bsi.instantiateBucket(b);
      reconfigured[bucketNo] = true;
    }
    realCacheSize.addAndGet(foundLen);
    buckets[bucketNo].addAllocation(foundOffset);
    usedSize += buckets[bucketNo].getItemAllocationSize();
    bucketSizeInfos[bucketSizeIndex].blockAllocated(b);
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:60,代码来源:BucketAllocator.java

示例15: testInsertUpdateDelete

import java.util.concurrent.atomic.AtomicLong; //导入方法依赖的package包/类
@Test
public void testInsertUpdateDelete() throws Exception {
  final int NTHREAD = 2;

  procStore.stop(false);
  fs.delete(logDir, true);

  org.apache.hadoop.conf.Configuration conf =
    new org.apache.hadoop.conf.Configuration(htu.getConfiguration());
  conf.setBoolean("hbase.procedure.store.wal.use.hsync", false);
  conf.setInt("hbase.procedure.store.wal.periodic.roll.msec", 10000);
  conf.setInt("hbase.procedure.store.wal.roll.threshold", 128 * 1024);

  fs.mkdirs(logDir);
  procStore = ProcedureTestingUtility.createWalStore(conf, fs, logDir);
  procStore.start(NTHREAD);
  procStore.recoverLease();

  LoadCounter loader = new LoadCounter();
  procStore.load(loader);
  assertEquals(0, loader.getMaxProcId());
  assertEquals(0, loader.getLoadedCount());
  assertEquals(0, loader.getCorruptedCount());

  final long LAST_PROC_ID = 9999;
  final Thread[] thread = new Thread[NTHREAD];
  final AtomicLong procCounter = new AtomicLong((long)Math.round(Math.random() * 100));
  for (int i = 0; i < thread.length; ++i) {
    thread[i] = new Thread() {
      @Override
      public void run() {
        Random rand = new Random();
        TestProcedure proc;
        do {
          proc = new TestProcedure(procCounter.addAndGet(1));
          // Insert
          procStore.insert(proc, null);
          // Update
          for (int i = 0, nupdates = rand.nextInt(10); i <= nupdates; ++i) {
            try { Thread.sleep(0, rand.nextInt(15)); } catch (InterruptedException e) {}
            procStore.update(proc);
          }
          // Delete
          procStore.delete(proc.getProcId());
        } while (proc.getProcId() < LAST_PROC_ID);
      }
    };
    thread[i].start();
  }

  for (int i = 0; i < thread.length; ++i) {
    thread[i].join();
  }

  procStore.getStoreTracker().dump();
  assertTrue(procCounter.get() >= LAST_PROC_ID);
  assertTrue(procStore.getStoreTracker().isEmpty());
  assertEquals(1, procStore.getActiveLogs().size());
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:60,代码来源:TestWALProcedureStore.java


注:本文中的java.util.concurrent.atomic.AtomicLong.addAndGet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。