java.util.concurrent.atomic.AtomicInteger.getAndAdd()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(164)

本文整理了Java中java.util.concurrent.atomic.AtomicInteger.getAndAdd()方法的一些代码示例,展示了AtomicInteger.getAndAdd()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AtomicInteger.getAndAdd()方法的具体详情如下:
包路径:java.util.concurrent.atomic.AtomicInteger
类名称:AtomicInteger
方法名:getAndAdd

AtomicInteger.getAndAdd介绍

[英]Atomically adds the given value to the current value.
[中]以原子方式将给定值添加到当前值。

代码示例

代码示例来源:origin: h2oai/h2o-2

Submitter() {
    int s = nextSubmitterSeed.getAndAdd(SEED_INCREMENT);
    seed = (s == 0) ? 1 : s; // ensure non-zero
  }
}

代码示例来源:origin: languagetool-org/languagetool

@Override
public AnalyzedToken next() {
 try {
  return anTokReadings[i.getAndAdd(1)];
 } catch (ArrayIndexOutOfBoundsException e) {
  throw new NoSuchElementException("No such element: " + i + ", element count: " + anTokReadings.length);
 }
}
@Override

代码示例来源:origin: btraceio/btrace

static int getAndAdd(AtomicInteger ai, int i) {
  if (ai instanceof BTraceAtomicInteger) {
    return ai.getAndAdd(i);
  } else {
    throw new IllegalArgumentException();
  }
}

代码示例来源:origin: apache/kafka

/**
 * Clear out all the in-flight requests for the given node and return them
 *
 * @param node The node
 * @return All the in-flight requests for that node that have been removed
 */
public Iterable<NetworkClient.InFlightRequest> clearAll(String node) {
  Deque<NetworkClient.InFlightRequest> reqs = requests.get(node);
  if (reqs == null) {
    return Collections.emptyList();
  } else {
    final Deque<NetworkClient.InFlightRequest> clearedRequests = requests.remove(node);
    inFlightRequestCount.getAndAdd(-clearedRequests.size());
    return () -> clearedRequests.descendingIterator();
  }
}

代码示例来源:origin: apache/geode

public MarsagliaRandom() {
 this((int) System.nanoTime() + seq.getAndAdd(129));
}

代码示例来源:origin: apache/geode

public XorShift32Random() {
 this((int) System.nanoTime() + seq.getAndAdd(129));
}

代码示例来源:origin: apache/storm

private void dropMessages(Iterator<TaskMessage> msgs) {
  // We consume the iterator by traversing and thus "emptying" it.
  int msgCount = iteratorSize(msgs);
  messagesLost.getAndAdd(msgCount);
  LOG.info("Dropping {} messages", msgCount);
}

代码示例来源:origin: apache/geode

public void incRequestInProgress(int threads) {
 if (this._stats != null) {
  this._stats.incInt(_REQUESTS_IN_PROGRESS, threads);
 } else {
  requestsInProgress.getAndAdd(threads);
 }
}

代码示例来源:origin: kaaproject/kaa

@Override
public void onSuccess(AppendBatchAsyncResultPojo result) {
 flumeSuccessLogCount.getAndAdd(size);
 callback.onSuccess();
}

代码示例来源:origin: ata4/disunity

public static BiMap<Integer, String> commonStrings(int version) throws IOException {
  // load default strings from resource files if required
  if (!commonStringMap.containsKey(version)) {
    AtomicInteger index = new AtomicInteger(1 << 31);
    String resourcePath = "/resources/strings/" + version + ".x.txt";
    try (BufferedReader br = resourceReader(resourcePath)) {
      commonStringMap.put(version, br.lines().collect(Collectors.toMap(
        value -> index.getAndAdd(value.length() + 1),
        value -> value
      )));
    } catch (NullPointerException ex) {
      throw new RuntimeException("No common strings file found for version " + version);
    }
  }
  return HashBiMap.create(commonStringMap.get(version));
}

代码示例来源:origin: apache/storm

@Override
public void operationComplete(ChannelFuture future) throws Exception {
  pendingMessages.addAndGet(0 - numMessages);
  if (future.isSuccess()) {
    LOG.debug("sent {} messages to {}", numMessages, dstAddressPrefixedName);
    messagesSent.getAndAdd(batch.size());
  } else {
    LOG.error("failed to send {} messages to {}: {}", numMessages, dstAddressPrefixedName,
         future.cause());
    closeChannelAndReconnect(future.channel());
    messagesLost.getAndAdd(numMessages);
  }
}

代码示例来源:origin: apache/kafka

/**
 * Append a set of records to the file. This method is not thread-safe and must be
 * protected with a lock.
 *
 * @param records The records to append
 * @return the number of bytes written to the underlying file
 */
public int append(MemoryRecords records) throws IOException {
  if (records.sizeInBytes() > Integer.MAX_VALUE - size.get())
    throw new IllegalArgumentException("Append of size " + records.sizeInBytes() +
        " bytes is too large for segment with current file position at " + size.get());
  int written = records.writeFullyTo(channel);
  size.getAndAdd(written);
  return written;
}

代码示例来源:origin: apache/storm

private Map<String, AtomicInteger> getScheduledCount(TopologyDetails topologyDetails) {
  String topoId = topologyDetails.getId();
  SchedulerAssignment assignment = cluster.getAssignmentById(topoId);
  Map<String, AtomicInteger> scheduledCount = new HashMap<>();
  if (assignment != null) {
    for (Map.Entry<WorkerSlot, Collection<ExecutorDetails>> entry :
      assignment.getSlotToExecutors().entrySet()) {
      String superId = entry.getKey().getNodeId();
      String rackId = superIdToRack.get(superId);
      scheduledCount.computeIfAbsent(rackId, (rid) -> new AtomicInteger(0))
        .getAndAdd(entry.getValue().size());
    }
  }
  return scheduledCount;
}

代码示例来源:origin: apache/storm

public LazyNodeSorting(TopologyDetails td, ExecutorDetails exec,
            List<String> favoredNodeIds, List<String> unFavoredNodeIds) {
  this.favoredNodeIds = favoredNodeIds;
  this.unFavoredNodeIds = unFavoredNodeIds;
  this.unFavoredNodeIds.removeAll(favoredNodeIds);
  skippedNodeIds.addAll(favoredNodeIds);
  skippedNodeIds.addAll(unFavoredNodeIds);
  this.td = td;
  this.exec = exec;
  String topoId = td.getId();
  SchedulerAssignment assignment = cluster.getAssignmentById(topoId);
  if (assignment != null) {
    for (Map.Entry<WorkerSlot, Collection<ExecutorDetails>> entry :
      assignment.getSlotToExecutors().entrySet()) {
      String superId = entry.getKey().getNodeId();
      perNodeScheduledCount.computeIfAbsent(superId, (sid) -> new AtomicInteger(0))
        .getAndAdd(entry.getValue().size());
    }
  }
  sortedRacks = sortRacks(exec, td);
}

代码示例来源:origin: bumptech/glide

@SuppressWarnings("WeakerAccess")
@Synthetic
synchronized void incrementPendingCallbacks(int count) {
 Preconditions.checkArgument(isDone(), "Not yet complete!");
 if (pendingCallbacks.getAndAdd(count) == 0 && engineResource != null) {
  engineResource.acquire();
 }
}

代码示例来源:origin: kaaproject/kaa

@Override
 public void onFailure(Throwable throwable) {
  flumeFailureLogCount.getAndAdd(size);
  LOG.warn("Failed to store record", throwable);
  if (throwable instanceof IOException) {
   callback.onConnectionError();
  } else if (throwable instanceof EventDeliveryException) {
   callback.onRemoteError();
  } else {
   callback.onInternalError();
  }
 }
}

代码示例来源:origin: apache/drill

@Override
public ByteBuf retain(int increment) {
 Preconditions.checkArgument(increment > 0, "retain(%d) argument is not positive", increment);
 if (isEmpty) {
  return this;
 }
 if (BaseAllocator.DEBUG) {
  historicalLog.recordEvent("retain(%d)", increment);
 }
 final int originalReferenceCount = refCnt.getAndAdd(increment);
 Preconditions.checkArgument(originalReferenceCount > 0);
 return this;
}

代码示例来源:origin: alipay/sofa-rpc

protected int sendHttpRequest(FullHttpRequest httpRequest, AbstractHttpClientHandler callback) {
  final int requestId = streamId.getAndAdd(2);
  Channel channel = this.channel.channel();
  responseChannelHandler.put(requestId, channel.write(httpRequest), callback);
  channel.flush();
  return requestId;
}

代码示例来源:origin: alipay/sofa-rpc

protected int sendHttpRequest(FullHttpRequest httpRequest, AbstractHttpClientHandler callback) {
  final int requestId = streamId.getAndAdd(2);
  Channel channel = this.channel.channel();
  responseChannelHandler.put(requestId, channel.write(httpRequest), callback);
  channel.flush();
  return requestId;
}

代码示例来源:origin: apache/ignite

@Override public void run() {
    doSleep(1000);
    //spi1.failSend = false;
    cnt.getAndAdd(c1.compute(c1.cluster().forNodeId(c2.cluster().localNode().id())).call(new TestClosure()));
  }
}, 1, "hang-thread");

相关文章