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

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

源代码1 项目: qpid-jms   文件: ProducerAndConsumerBench.java
private void publishMessages(AtomicLong count) throws Exception {
    JmsConnection connection = (JmsConnection) factory.createConnection();
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createQueue(getDestinationName());

    MessageProducer producer = session.createProducer(queue);
    producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

    while (count.getAndDecrement() > 0) {
        BytesMessage message = session.createBytesMessage();
        message.writeBytes(payload);
        producer.send(message);
        if ((count.get() % 10000) == 0) {
            LOG.info("Sent message: {}", NUM_SENDS - count.get());
        }
    }
    producer.close();
    connection.close();
}
 
源代码2 项目: JavaCommon   文件: AtomicBooleanDemo.java
public static void main(String[] args) {
    AtomicBoolean atomicBoolean = new AtomicBoolean();
    atomicBoolean.getAndSet(true);

    AtomicLong atomicLong = new AtomicLong();
    atomicLong.getAndDecrement();

    AtomicInteger atomicInteger = new AtomicInteger();
    atomicInteger.incrementAndGet();
}
 
public void decreaseAccountLoginAttempts(ServletRequest request) {
    AtomicLong initValue = new AtomicLong(maxLoginAttempts);
    AtomicLong remainLoginAttempts = accountLockMap.putIfAbsent(getUsername(request), new AtomicLong(maxLoginAttempts));
    if (remainLoginAttempts == null) {
        remainLoginAttempts = initValue;
    }
    remainLoginAttempts.getAndDecrement();
    accountLockMap.put(getUsername(request), remainLoginAttempts);
}
 
源代码4 项目: bazel-buildfarm   文件: Extract.java
static Runnable blobGetter(
    Path root,
    String instanceName,
    Digest digest,
    ByteStreamStub bsStub,
    AtomicLong outstandingOperations,
    ListeningScheduledExecutorService retryService) {
  if (digest.getSizeBytes() == 0) {
    return () -> outstandingOperations.getAndDecrement();
  }
  return new Runnable() {
    @Override
    public void run() {
      Path file = root.resolve(digest.getHash());
      try {
        if (!Files.exists(file) || Files.size(file) != digest.getSizeBytes()) {
          System.out.println("Getting blob " + digest.getHash() + "/" + digest.getSizeBytes());
          try (OutputStream out = Files.newOutputStream(file)) {
            try (InputStream in = newInput(instanceName, digest, bsStub, retryService)) {
              ByteStreams.copy(in, out);
            }
          }
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
      outstandingOperations.getAndDecrement();
    }
  };
}