本文整理了Java中java.util.concurrent.atomic.AtomicInteger.get()
方法的一些代码示例,展示了AtomicInteger.get()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AtomicInteger.get()
方法的具体详情如下:
包路径:java.util.concurrent.atomic.AtomicInteger
类名称:AtomicInteger
方法名:get
[英]Gets the current value.
[中]获取当前值。
代码示例来源:origin: ReactiveX/RxJava
public final boolean fastEnter() {
return wip.get() == 0 && wip.compareAndSet(0, 1);
}
代码示例来源:origin: apache/incubator-dubbo
private boolean isSkip() {
int skip = connectSkip.get(); // Growth of skipping times
if (skip >= 10) { // If the number of skipping times increases by more than 10, take the random number
if (connectRandom == 0) {
connectRandom = ThreadLocalRandom.current().nextInt(10);
}
skip = 10 + connectRandom;
}
if (connectSkipped.getAndIncrement() < skip) { // Check the number of skipping times
return true;
}
connectSkip.incrementAndGet();
connectSkipped.set(0);
connectRandom = 0;
return false;
}
代码示例来源:origin: alibaba/druid
public void beforeOpen() {
int invoking = openingCount.incrementAndGet();
for (;;) {
int max = openingMax.get();
if (invoking > max) {
if (openingMax.compareAndSet(max, invoking)) {
break;
}
} else {
break;
}
}
openCount.incrementAndGet();
lastOpenTime = System.currentTimeMillis();
}
代码示例来源: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: spring-projects/spring-framework
@Test
public void verifyDirtiesContextBehavior() throws Exception {
runTestClassAndAssertStats(ClassLevelDirtiesContextWithCleanMethodsAndDefaultModeTestCase.class, 1);
assertContextCacheStatistics("after class-level @DirtiesContext with clean test method and default class mode",
0, cacheHits.get(), cacheMisses.incrementAndGet());
}
代码示例来源:origin: spring-projects/spring-framework
private static int count(Iterable<Node> nodes) {
assertNotNull(nodes);
AtomicInteger count = new AtomicInteger();
nodes.forEach(n -> count.incrementAndGet());
return count.get();
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public void run() {
counter.incrementAndGet();
System.out.println("counter: " + counter.get());
inner.schedule(this);
}
代码示例来源: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: google/guava
public void testForEachPair_parallel() {
Stream<String> streamA = IntStream.range(0, 100000).mapToObj(String::valueOf).parallel();
Stream<Integer> streamB = IntStream.range(0, 100000).mapToObj(i -> i).parallel();
AtomicInteger count = new AtomicInteger(0);
Streams.forEachPair(
streamA,
streamB,
(a, b) -> {
count.incrementAndGet();
Truth.assertThat(a.equals(String.valueOf(b))).isTrue();
});
Truth.assertThat(count.get()).isEqualTo(100000);
// of course, this test doesn't prove that anything actually happened in parallel...
}
代码示例来源:origin: alibaba/druid
public void beforeExecute() {
int invoking = runningCount.incrementAndGet();
for (;;) {
int max = concurrentMax.get();
if (invoking > max) {
if (concurrentMax.compareAndSet(max, invoking)) {
break;
}
} else {
break;
}
}
count.incrementAndGet();
lastSampleTime = System.currentTimeMillis();
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public void run() {
counter.incrementAndGet();
System.out.println("counter: " + counter.get());
inner.schedule(this);
}
代码示例来源:origin: apache/incubator-dubbo
private boolean isSkip() {
int skip = connectSkip.get(); // Growth of skipping times
if (skip >= 10) { // If the number of skipping times increases by more than 10, take the random number
if (connectRandom == 0) {
connectRandom = ThreadLocalRandom.current().nextInt(10);
}
skip = 10 + connectRandom;
}
if (connectSkipped.getAndIncrement() < skip) { // Check the number of skipping times
return true;
}
connectSkip.incrementAndGet();
connectSkipped.set(0);
connectRandom = 0;
return false;
}
代码示例来源:origin: ReactiveX/RxJava
public final boolean fastEnter() {
return wip.get() == 0 && wip.compareAndSet(0, 1);
}
代码示例来源: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() {
final AtomicInteger nexts = new AtomicInteger();
try {
Observable<String> origin = Observable.unsafeCreate(new FuncWithErrors(NUM_RETRIES));
TestObserver<String> to = new TestObserver<String>();
origin.retry()
.observeOn(Schedulers.computation()).subscribe(to);
to.awaitTerminalEvent(2500, TimeUnit.MILLISECONDS);
List<String> onNextEvents = new ArrayList<String>(to.values());
if (onNextEvents.size() != NUM_RETRIES + 2) {
for (Throwable t : to.errors()) {
onNextEvents.add(t.toString());
}
for (long err = to.completions(); err != 0; err--) {
onNextEvents.add("onComplete");
}
data.put(j, onNextEvents);
}
} catch (Throwable t) {
timeouts.incrementAndGet();
System.out.println(j + " | " + cdl.getCount() + " !!! " + nexts.get());
}
cdl.countDown();
}
});
代码示例来源: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: google/guava
@Override
public void onRemoval(RemovalNotification<Integer, AtomicInteger> notification) {
if (notification.wasEvicted()) {
evictionCount.incrementAndGet();
totalSum.addAndGet(notification.getValue().get());
}
}
};
代码示例来源:origin: netty/netty
static boolean reserveSpace(AtomicInteger availableSharedCapacity, int space) {
assert space >= 0;
for (;;) {
int available = availableSharedCapacity.get();
if (available < space) {
return false;
}
if (availableSharedCapacity.compareAndSet(available, available - space)) {
return true;
}
}
}
}
代码示例来源: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: prestodb/presto
@Test
public void testRevocationAlreadyRequested()
{
AtomicInteger counter = new AtomicInteger();
OperatorContext operatorContext = TestingOperatorContext.create(scheduledExecutor);
LocalMemoryContext revocableMemoryContext = operatorContext.localRevocableMemoryContext();
revocableMemoryContext.setBytes(1000);
// when memory revocation is already requested setting a listener should immediately execute it
operatorContext.requestMemoryRevoking();
operatorContext.setMemoryRevocationRequestListener(() -> counter.incrementAndGet());
assertTrue(operatorContext.isMemoryRevokingRequested());
assertEquals(counter.get(), 1);
}
内容来源于网络,如有侵权,请联系作者删除!