java.util.concurrent.atomic.AtomicInteger#getAndDecrement()源码实例Demo

下面列出了java.util.concurrent.atomic.AtomicInteger#getAndDecrement() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

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;
}
 
源代码2 项目: netbeans   文件: VerifyClassLinkage.java
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);
        }
    }
}
 
源代码3 项目: openjdk-8   文件: LinkedBlockingQueue.java
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;
}
 
源代码4 项目: strimzi-kafka-operator   文件: KafkaRollerTest.java
@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));
}
 
源代码5 项目: dble   文件: AlertBlockQueue.java
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;
}
 
源代码6 项目: jdk-1.7-annotated   文件: LinkedBlockingQueue.java
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;
}
 
源代码7 项目: jdk8u-jdk   文件: LinkedBlockingQueue.java
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;
}
 
源代码8 项目: hottub   文件: LinkedBlockingQueue.java
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;
}
 
源代码9 项目: j2objc   文件: LinkedBlockingQueue.java
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;
}
 
源代码10 项目: jdk8u_jdk   文件: LinkedBlockingQueue.java
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;
}
 
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;
}
 
源代码12 项目: openjdk-jdk9   文件: LinkedBlockingQueue.java
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;
}
 
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;
}
 
源代码14 项目: rome   文件: AtomicIntegerDemo.java
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);
}
 
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;
}
 
源代码16 项目: okhttp-OkGo   文件: PriorityBlockingQueue.java
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;
}
 
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;
}
 
源代码18 项目: openjdk-jdk8u   文件: LinkedBlockingQueue.java
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;
}
 
源代码19 项目: jdk8u-dev-jdk   文件: LinkedBlockingQueue.java
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;
}
 
源代码20 项目: besu   文件: AbstractMessageTaskTest.java
@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);
}