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

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

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

AtomicInteger.getAndSet介绍

[英]Atomically sets to the given value and returns the old value.
[中]原子设置为给定值并返回旧值。

代码示例

代码示例来源:origin: apache/incubator-druid

@Override
public int getAndResetFailedAssignCount()
{
 return failedAssignCount.getAndSet(0);
}

代码示例来源:origin: apache/incubator-druid

@Override
public int getAndResetFailedAssignCount()
{
 return failedAssignCount.getAndSet(0);
}

代码示例来源:origin: alibaba/druid

public static int get(AtomicInteger counter, boolean reset) {
    if (reset) {
      return counter.getAndSet(0);
    } else {
      return counter.get();
    }
  }
}

代码示例来源:origin: hibernate/hibernate-orm

public static int getAndResetInvocationCount() {
    return COUNTER.getAndSet( 0 );
  }
}

代码示例来源:origin: prestodb/presto

public synchronized void setPartitionedSplitCount(int partitionedSplitCount)
{
  if (partitionedSplitCount < 0) {
    int oldValue = localPartitionedSplitCount.getAndSet(0);
    nodeTotalPartitionedSplitCount.addAndGet(-oldValue);
    throw new IllegalArgumentException("partitionedSplitCount is negative");
  }
  int oldValue = localPartitionedSplitCount.getAndSet(partitionedSplitCount);
  nodeTotalPartitionedSplitCount.addAndGet(partitionedSplitCount - oldValue);
}

代码示例来源:origin: facebook/litho

void acquire() {
 if (mRefCount.getAndSet(1) != 0) {
  throw new RuntimeException(
    "Tried to acquire a LayoutOutput that already had a non-zero ref count!");
 }
}

代码示例来源:origin: weibocom/motan

@Override
  public String statisticCallback() {
    int count = rejectCounter.getAndSet(0);
    if (count > 0) {
      return String.format("type: motan name: reject_request_pool total_count: %s reject_count: %s", threadPoolExecutor.getPoolSize(), count);
    } else {
      return null;
    }
  }
}

代码示例来源:origin: weibocom/motan

@Override
  public String statisticCallback() {
    int count = rejectCounter.getAndSet(0);
    if (count > 0) {
      return String.format("type: motan name: reject_request total_count: %s reject_count: %s", totalCounter.get(), count);
    } else {
      return null;
    }
  }
}

代码示例来源:origin: weibocom/motan

@Override
  public String statisticCallback() {
    int count = rejectCounter.getAndSet(0);
    if (count > 0) {
      return String.format("type: motan name: reject_request_pool total_count: %s reject_count: %s", threadPoolExecutor.getPoolSize(), count);
    } else {
      return null;
    }
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Override
public void onNext(Notification<T> args) {
  if (waiting.getAndSet(0) == 1 || !args.isOnNext()) {
    Notification<T> toOffer = args;
    while (!buf.offer(toOffer)) {
      Notification<T> concurrentItem = buf.poll();
      // in case if we won race condition with onComplete/onError method
      if (concurrentItem != null && !concurrentItem.isOnNext()) {
        toOffer = concurrentItem;
      }
    }
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Override
public void onNext(Notification<T> args) {
  if (waiting.getAndSet(0) == 1 || !args.isOnNext()) {
    Notification<T> toOffer = args;
    while (!buf.offer(toOffer)) {
      Notification<T> concurrentItem = buf.poll();
      // in case if we won race condition with onComplete/onError method
      if (concurrentItem != null && !concurrentItem.isOnNext()) {
        toOffer = concurrentItem;
      }
    }
  }
}

代码示例来源:origin: prestodb/presto

public void cleanup()
{
  int leakedSplits = localPartitionedSplitCount.getAndSet(0);
  if (leakedSplits == 0) {
    return;
  }
  log.error("BUG! %s for %s leaked with %s partitioned splits.  Cleaning up so server can continue to function.",
      getClass().getName(),
      taskId,
      leakedSplits);
  nodeTotalPartitionedSplitCount.addAndGet(-leakedSplits);
}

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

@Override
public Object getState() {
  LOG.debug("Getting metrics for client connection to {}", dstAddressPrefixedName);
  HashMap<String, Object> ret = new HashMap<String, Object>();
  ret.put("reconnects", totalConnectionAttempts.getAndSet(0));
  ret.put("sent", messagesSent.getAndSet(0));
  ret.put("pending", pendingMessages.get());
  ret.put("lostOnSend", messagesLost.getAndSet(0));
  ret.put("dest", dstAddress.toString());
  String src = srcAddressName();
  if (src != null) {
    ret.put("src", src);
  }
  return ret;
}

代码示例来源:origin: facebook/litho

static ViewNodeInfo acquire() {
 final ViewNodeInfo viewNodeInfo = ComponentsPools.acquireViewNodeInfo();
 if (viewNodeInfo.mReferenceCount.getAndSet(1) != 0) {
  throw new IllegalStateException("The ViewNodeInfo reference acquired from the pool " +
    " wasn't correctly released.");
 }
 return viewNodeInfo;
}

代码示例来源:origin: facebook/litho

static NodeInfo acquire() {
 final NodeInfo nodeInfo = ComponentsPools.acquireNodeInfo();
 if (nodeInfo.mReferenceCount.getAndSet(1) != 0) {
  throw new IllegalStateException("The NodeInfo reference acquired from the pool " +
    " wasn't correctly released.");
 }
 return nodeInfo;
}

代码示例来源:origin: redisson/redisson

@Override
public void onNext(Notification<T> args) {
  if (waiting.getAndSet(0) == 1 || !args.isOnNext()) {
    Notification<T> toOffer = args;
    while (!buf.offer(toOffer)) {
      Notification<T> concurrentItem = buf.poll();
      // in case if we won race condition with onComplete/onError method
      if (concurrentItem != null && !concurrentItem.isOnNext()) {
        toOffer = concurrentItem;
      }
    }
  }
}

代码示例来源:origin: redisson/redisson

@Override
public void onNext(Notification<T> args) {
  if (waiting.getAndSet(0) == 1 || !args.isOnNext()) {
    Notification<T> toOffer = args;
    while (!buf.offer(toOffer)) {
      Notification<T> concurrentItem = buf.poll();
      // in case if we won race condition with onComplete/onError method
      if (concurrentItem != null && !concurrentItem.isOnNext()) {
        toOffer = concurrentItem;
      }
    }
  }
}

代码示例来源:origin: weibocom/motan

public synchronized void removeProvider(Provider<?> provider) {
  String serviceKey = MotanFrameworkUtil.getServiceKey(provider.getUrl());
  providers.remove(serviceKey);
  List<Method> methods = ReflectUtil.getPublicMethod(provider.getInterface());
  int publicMethodCount = methods.size();
  methodCounter.getAndSet(methodCounter.get() - publicMethodCount);
  LoggerUtil.info("RequestRouter removeProvider: url=" + provider.getUrl() + " all_public_method_count=" + methodCounter.get());
}

代码示例来源:origin: jeasonlzy/okhttp-OkGo

public void clear() {
  fullyLock();
  try {
    for (Node<E> p, h = head; (p = h.next) != null; h = p) {
      h.next = h;
      p.setValue(null);
    }
    head = last;
    // assert head.item == null && head.next == null;
    if (count.getAndSet(0) == capacity) notFull.signal();
  } finally {
    fullyUnlock();
  }
}

代码示例来源:origin: neo4j/neo4j

@Override
public void progress( ImportStage stage, int percent )
{
  if ( percent > 100 )
  {
    fail( "Expected percentage to be 0..100% but was " + percent );
  }
  AtomicInteger stageProgress = progress.computeIfAbsent( stage, s -> new AtomicInteger() );
  int previous = stageProgress.getAndSet( percent );
  if ( previous > percent )
  {
    fail( "Progress should go forwards only, but went from " + previous + " to " + percent );
  }
}

相关文章