Java Code Examples for java.util.concurrent.atomic.AtomicInteger#getAndDecrement()
The following examples show how to use
java.util.concurrent.atomic.AtomicInteger#getAndDecrement() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: jdk1.8-source-analysis File: LinkedBlockingQueue.java License: Apache License 2.0 | 6 votes |
public E take() throws InterruptedException { E x; int c = -1; final AtomicInteger count = this.count; final ReentrantLock takeLock = this.takeLock; takeLock.lockInterruptibly(); try { while (count.get() == 0) { notEmpty.await(); } x = dequeue(); c = count.getAndDecrement(); if (c > 1) notEmpty.signal(); } finally { takeLock.unlock(); } if (c == capacity) signalNotFull(); return x; }
Example 2
Source Project: netbeans File: VerifyClassLinkage.java License: Apache License 2.0 | 6 votes |
private void verify(String clazz, byte[] data, Map<String,Boolean> loadable, ClassLoader loader, AtomicInteger maxWarn) throws IOException, BuildException { //log("Verifying linkage of " + clazz.replace('/', '.'), Project.MSG_DEBUG); Set<String> dependencies = dependencies(data); //System.err.println(clazz + " -> " + dependencies); for (String clazz2 : dependencies) { Boolean exists = loadable.get(clazz2); if (exists == null) { exists = loader.getResource(clazz2.replace('.', '/') + ".class") != null; loadable.put(clazz2, exists); } if (!exists) { String message = clazz + " cannot access " + clazz2; if (failOnError) { throw new BuildException(message, getLocation()); } else if (maxWarn.getAndDecrement() > 0) { log("Warning: " + message, Project.MSG_WARN); } else { log("(additional warnings not reported)", Project.MSG_WARN); return; } } else { //log("Working reference to " + clazz2, Project.MSG_DEBUG); } } }
Example 3
Source Project: openjdk-8 File: LinkedBlockingQueue.java License: GNU General Public License v2.0 | 6 votes |
public E poll() { final AtomicInteger count = this.count; if (count.get() == 0) return null; E x = null; int c = -1; final ReentrantLock takeLock = this.takeLock; takeLock.lock(); try { if (count.get() > 0) { x = dequeue(); c = count.getAndDecrement(); if (c > 1) notEmpty.signal(); } } finally { takeLock.unlock(); } if (c == capacity) signalNotFull(); return x; }
Example 4
Source Project: strimzi-kafka-operator File: KafkaRollerTest.java License: Apache License 2.0 | 6 votes |
@Test public void testControllerNotInitiallyRollable(VertxTestContext testContext) { PodOperator podOps = mockPodOps(podId -> succeededFuture()); StatefulSet sts = buildStatefulSet(); AtomicInteger count = new AtomicInteger(2); TestingKafkaRoller kafkaRoller = new TestingKafkaRoller(sts, null, null, podOps, null, null, null, brokerId -> { if (brokerId == 2) { boolean b = count.getAndDecrement() == 0; log.info("Can broker {} be rolled now ? {}", brokerId, b); return succeededFuture(b); } else { return succeededFuture(true); } }, 2); doSuccessfulRollingRestart(testContext, kafkaRoller, asList(0, 1, 2, 3, 4), asList(0, 1, 3, 4, 2)); }
Example 5
Source Project: dble File: AlertBlockQueue.java License: GNU General Public License v2.0 | 6 votes |
public E poll() { final AtomicInteger count = this.count; if (count.get() == 0) return null; E x = null; int c = -1; final ReentrantLock takeLock = this.takeLock; takeLock.lock(); try { if (count.get() > 0) { x = dequeue(); c = count.getAndDecrement(); if (c > 1) notEmpty.signal(); } } finally { takeLock.unlock(); } if (c == capacity) signalNotFull(); return x; }
Example 6
Source Project: jdk-1.7-annotated File: LinkedBlockingQueue.java License: Apache License 2.0 | 6 votes |
public E poll() { final AtomicInteger count = this.count; if (count.get() == 0) return null; E x = null; int c = -1; final ReentrantLock takeLock = this.takeLock; takeLock.lock(); try { if (count.get() > 0) { x = dequeue(); c = count.getAndDecrement(); if (c > 1) notEmpty.signal(); } } finally { takeLock.unlock(); } if (c == capacity) signalNotFull(); return x; }
Example 7
Source Project: jdk8u-jdk File: LinkedBlockingQueue.java License: GNU General Public License v2.0 | 6 votes |
public E poll() { final AtomicInteger count = this.count; if (count.get() == 0) return null; E x = null; int c = -1; final ReentrantLock takeLock = this.takeLock; takeLock.lock(); try { if (count.get() > 0) { x = dequeue(); c = count.getAndDecrement(); if (c > 1) notEmpty.signal(); } } finally { takeLock.unlock(); } if (c == capacity) signalNotFull(); return x; }
Example 8
Source Project: hottub File: LinkedBlockingQueue.java License: GNU General Public License v2.0 | 6 votes |
public E take() throws InterruptedException { E x; int c = -1; final AtomicInteger count = this.count; final ReentrantLock takeLock = this.takeLock; takeLock.lockInterruptibly(); try { while (count.get() == 0) { notEmpty.await(); } x = dequeue(); c = count.getAndDecrement(); if (c > 1) notEmpty.signal(); } finally { takeLock.unlock(); } if (c == capacity) signalNotFull(); return x; }
Example 9
Source Project: j2objc File: LinkedBlockingQueue.java License: Apache License 2.0 | 6 votes |
public E take() throws InterruptedException { E x; int c = -1; final AtomicInteger count = this.count; final ReentrantLock takeLock = this.takeLock; takeLock.lockInterruptibly(); try { while (count.get() == 0) { notEmpty.await(); } x = dequeue(); c = count.getAndDecrement(); if (c > 1) notEmpty.signal(); } finally { takeLock.unlock(); } if (c == capacity) signalNotFull(); return x; }
Example 10
Source Project: jdk8u_jdk File: LinkedBlockingQueue.java License: GNU General Public License v2.0 | 6 votes |
public E poll() { final AtomicInteger count = this.count; if (count.get() == 0) return null; E x = null; int c = -1; final ReentrantLock takeLock = this.takeLock; takeLock.lock(); try { if (count.get() > 0) { x = dequeue(); c = count.getAndDecrement(); if (c > 1) notEmpty.signal(); } } finally { takeLock.unlock(); } if (c == capacity) signalNotFull(); return x; }
Example 11
Source Project: floodlight_with_topoguard File: PriorityPendingQueue.java License: Apache License 2.0 | 6 votes |
public E take() throws InterruptedException { E x; int c = -1; final AtomicInteger count = this.count; final ReentrantLock takeLock = this.takeLock; takeLock.lockInterruptibly(); try { try { while (count.get() == 0) notEmpty.await(); } catch (InterruptedException ie) { notEmpty.signal(); // propagate to a non-interrupted thread throw ie; } x = extract(); c = count.getAndDecrement(); if (c > 1) notEmpty.signal(); } finally { takeLock.unlock(); } if (c == capacity) signalNotFull(); return x; }
Example 12
Source Project: openjdk-jdk9 File: LinkedBlockingQueue.java License: GNU General Public License v2.0 | 6 votes |
public E take() throws InterruptedException { E x; int c = -1; final AtomicInteger count = this.count; final ReentrantLock takeLock = this.takeLock; takeLock.lockInterruptibly(); try { while (count.get() == 0) { notEmpty.await(); } x = dequeue(); c = count.getAndDecrement(); if (c > 1) notEmpty.signal(); } finally { takeLock.unlock(); } if (c == capacity) signalNotFull(); return x; }
Example 13
Source Project: android-open-project-demo File: PriorityObjectBlockingQueue.java License: Apache License 2.0 | 6 votes |
public E poll(long timeout, TimeUnit unit) throws InterruptedException { E x = null; int c = -1; long nanos = unit.toNanos(timeout); final AtomicInteger count = this.count; final ReentrantLock takeLock = this.takeLock; takeLock.lockInterruptibly(); try { while (count.get() == 0) { if (nanos <= 0) return null; nanos = notEmpty.awaitNanos(nanos); } x = opQueue(null); c = count.getAndDecrement(); if (c > 1) notEmpty.signal(); } finally { takeLock.unlock(); } if (c == capacity) signalNotFull(); return x; }
Example 14
Source Project: rome File: AtomicIntegerDemo.java License: Apache License 2.0 | 6 votes |
public static void main(String[] args) { int temValue = 0; AtomicInteger value = new AtomicInteger(0); temValue = value.getAndSet(3); // 首先get,获取到当前value的值为0,并赋值给temValue,之后设置新值3,此时value为3 System.out.println("temValue = " + temValue + " value = " + value); temValue = value.getAndIncrement(); System.out.println("temValue = " + temValue + " value = " + value); temValue = value.getAndDecrement(); System.out.println("temValue = " + temValue + " value = " + value); temValue = value.getAndAdd(10); System.out.println("temValue = " + temValue + " value = " + value); }
Example 15
Source Project: gemfirexd-oss File: ForceableLinkedBlockingQueue.java License: Apache License 2.0 | 6 votes |
public E take() throws InterruptedException { E x; int c = -1; final AtomicInteger count = this.count; final ReentrantLock takeLock = this.takeLock; takeLock.lockInterruptibly(); try { while (count.get() == 0) { notEmpty.await(); } x = dequeue(); c = count.getAndDecrement(); if (c > 1) notEmpty.signal(); } finally { takeLock.unlock(); } if (c <= capacity) // GEMFIRE changed == to <= signalNotFull(); return x; }
Example 16
Source Project: okhttp-OkGo File: PriorityBlockingQueue.java License: Apache License 2.0 | 6 votes |
public E poll() { final AtomicInteger count = this.count; if (count.get() == 0) return null; E x = null; int c = -1; final ReentrantLock takeLock = this.takeLock; takeLock.lock(); try { if (count.get() > 0) { x = opQueue(null); c = count.getAndDecrement(); if (c > 1) notEmpty.signal(); } } finally { takeLock.unlock(); } if (c == capacity) signalNotFull(); return x; }
Example 17
Source Project: gemfirexd-oss File: ForceableLinkedBlockingQueue.java License: Apache License 2.0 | 6 votes |
public E take() throws InterruptedException { E x; int c = -1; final AtomicInteger count = this.count; final ReentrantLock takeLock = this.takeLock; takeLock.lockInterruptibly(); try { while (count.get() == 0) { notEmpty.await(); } x = dequeue(); c = count.getAndDecrement(); if (c > 1) notEmpty.signal(); } finally { takeLock.unlock(); } if (c <= capacity) // GEMFIRE changed == to <= signalNotFull(); return x; }
Example 18
Source Project: openjdk-jdk8u File: LinkedBlockingQueue.java License: GNU General Public License v2.0 | 6 votes |
public E take() throws InterruptedException { E x; int c = -1; final AtomicInteger count = this.count; final ReentrantLock takeLock = this.takeLock; takeLock.lockInterruptibly(); try { while (count.get() == 0) { notEmpty.await(); } x = dequeue(); c = count.getAndDecrement(); if (c > 1) notEmpty.signal(); } finally { takeLock.unlock(); } if (c == capacity) signalNotFull(); return x; }
Example 19
Source Project: jdk8u-dev-jdk File: LinkedBlockingQueue.java License: GNU General Public License v2.0 | 6 votes |
public E take() throws InterruptedException { E x; int c = -1; final AtomicInteger count = this.count; final ReentrantLock takeLock = this.takeLock; takeLock.lockInterruptibly(); try { while (count.get() == 0) { notEmpty.await(); } x = dequeue(); c = count.getAndDecrement(); if (c > 1) notEmpty.signal(); } finally { takeLock.unlock(); } if (c == capacity) signalNotFull(); return x; }
Example 20
Source Project: besu File: AbstractMessageTaskTest.java License: Apache License 2.0 | 5 votes |
@Before public void setupTest() { peersDoTimeout = new AtomicBoolean(false); peerCountToTimeout = new AtomicInteger(0); ethPeers = spy(new EthPeers(EthProtocol.NAME, TestClock.fixed(), metricsSystem)); final EthMessages ethMessages = new EthMessages(); final EthScheduler ethScheduler = new DeterministicEthScheduler( () -> peerCountToTimeout.getAndDecrement() > 0 || peersDoTimeout.get()); ethContext = new EthContext(ethPeers, ethMessages, ethScheduler); final SyncState syncState = new SyncState(blockchain, ethContext.getEthPeers()); transactionPool = TransactionPoolFactory.createTransactionPool( protocolSchedule, protocolContext, ethContext, TestClock.fixed(), metricsSystem, syncState, Wei.of(1), TransactionPoolConfiguration.builder().build(), true, Optional.empty()); ethProtocolManager = EthProtocolManagerTestUtil.create( blockchain, ethScheduler, protocolContext.getWorldStateArchive(), transactionPool, EthProtocolConfiguration.defaultConfig(), ethPeers, ethMessages, ethContext); }