java.util.concurrent.atomic.AtomicInteger类的使用及代码示例

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

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

AtomicInteger介绍

[英]An int value that may be updated atomically. See the java.util.concurrent.atomic package specification for description of the properties of atomic variables. An AtomicInteger is used in applications such as atomically incremented counters, and cannot be used as a replacement for an java.lang.Integer. However, this class does extend Number to allow uniform access by tools and utilities that deal with numerically-based classes.
[中]可以原子更新的int值。请参阅java。util。同时发生的描述原子变量属性的原子包规范。AtomicInteger用于诸如原子递增计数器之类的应用程序中,不能用作java的替代品。lang.Integer。然而,该类确实扩展了数字,以允许处理基于数字的类的工具和实用程序统一访问。

代码示例

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

@Override
  public void run() {
    if (wip.incrementAndGet() == 2) {
      emit();
      if (wip.decrementAndGet() == 0) {
        downstream.onComplete();
      }
    }
  }
}

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

@Override
public void onComplete() {
  threadsRunning.incrementAndGet();
  System.out.println(">>> Busyobserver received onComplete");
  onComplete = true;
  int concurrentThreads = threadsRunning.get();
  int maxThreads = maxConcurrentThreads.get();
  if (concurrentThreads > maxThreads) {
    maxConcurrentThreads.compareAndSet(maxThreads, concurrentThreads);
  }
  threadsRunning.decrementAndGet();
}

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

public FlowableAutoConnect(ConnectableFlowable<? extends T> source,
    int numberOfSubscribers,
    Consumer<? super Disposable> connection) {
  this.source = source;
  this.numberOfSubscribers = numberOfSubscribers;
  this.connection = connection;
  this.clients = new AtomicInteger();
}

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

@Override
  public void run() {
    c.decrementAndGet();
    while (c.get() != 0) { }
  }
});

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

@Test
public void testUnsubscribeOnNestedTakeAndSyncInfiniteStream() throws InterruptedException {
  final AtomicInteger subscribeCounter = new AtomicInteger();
  final AtomicInteger sentEventCounter = new AtomicInteger();
  doTestUnsubscribeOnNestedTakeAndAsyncInfiniteStream(SYNC_INFINITE_OBSERVABLE_OF_EVENT(2, subscribeCounter, sentEventCounter), subscribeCounter);
  Thread.sleep(500);
  assertEquals(39, sentEventCounter.get());
}

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

@Override
  public void accept(Disposable d) {
    subscribed.getAndIncrement();
  }
})

代码示例来源:origin: iluwatar/java-design-patterns

/**
 * Constructor
 */
public Oliphaunt() {
 id = counter.incrementAndGet();
 try {
  Thread.sleep(1000);
 } catch (InterruptedException e) {
  e.printStackTrace();
 }
}

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

@Override
public void run() {
  counter.incrementAndGet();
  System.out.println("counter: " + counter.get());
  inner.schedule(this);
}

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

@Override
public void onNext(Integer t) {
  // Consume after sleep for 1 ms
  try {
    Thread.sleep(1);
  } catch (InterruptedException e) {
    // ignored
  }
  if (counter.getAndIncrement() % 100 == 0) {
    System.out.println("testIssue2890NoStackoverflow -> " + counter.get());
  };
}

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

@Override
  public void onNext(Integer n) {
    if (depth.get() < MAX_STACK_DEPTH) {
      depth.set(Thread.currentThread().getStackTrace().length);
      a.onNext(n + 1);
    }
  }
});

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

@Override
  public void accept(Integer d) {
    dispose.set(d);
  }
});

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

@Test
public void testUnsubscribeOnNestedTakeAndSyncInfiniteStream() throws InterruptedException {
  final AtomicInteger subscribeCounter = new AtomicInteger();
  final AtomicInteger sentEventCounter = new AtomicInteger();
  doTestUnsubscribeOnNestedTakeAndAsyncInfiniteStream(SYNC_INFINITE_OBSERVABLE_OF_EVENT(2, subscribeCounter, sentEventCounter), subscribeCounter);
  Thread.sleep(500);
  assertEquals(39, sentEventCounter.get());
}

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

@Override
  public void run() {
    c.decrementAndGet();
    while (c.get() != 0) { }
  }
});

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

@Override
  public void accept(Disposable d) {
    subscribed.getAndIncrement();
  }
})

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

@Override
  public void accept(Integer n) {
    count.incrementAndGet();
  }
});

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

@Override
public void run() {
  counter.incrementAndGet();
  System.out.println("counter: " + counter.get());
  inner.schedule(this);
}

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

@Override
  public void accept(Integer v) {
    System.out.println("Value: " + v);
    lastValue.set(v);
  }
});

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

@Test
public void testUnsubscribeOnNestedTakeAndAsyncInfiniteStream() throws InterruptedException {
  final AtomicInteger subscribeCounter = new AtomicInteger();
  final AtomicInteger sentEventCounter = new AtomicInteger();
  doTestUnsubscribeOnNestedTakeAndAsyncInfiniteStream(ASYNC_INFINITE_OBSERVABLE_OF_EVENT(2, subscribeCounter, sentEventCounter), subscribeCounter);
  Thread.sleep(500);
  assertEquals(39, sentEventCounter.get());
}

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

@Override
  public void run() {
    if (wip.incrementAndGet() == 2) {
      emit();
      if (wip.decrementAndGet() == 0) {
        downstream.onComplete();
      }
    }
  }
}

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

@Override
public void onComplete() {
  threadsRunning.incrementAndGet();
  System.out.println(">>> Busyobserver received onComplete");
  onComplete = true;
  int concurrentThreads = threadsRunning.get();
  int maxThreads = maxConcurrentThreads.get();
  if (concurrentThreads > maxThreads) {
    maxConcurrentThreads.compareAndSet(maxThreads, concurrentThreads);
  }
  threadsRunning.decrementAndGet();
}

相关文章