Java Code Examples for java.util.concurrent.atomic.AtomicLong#getAndDecrement()

The following examples show how to use java.util.concurrent.atomic.AtomicLong#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
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();
}
 
Example 2
Source Project: JavaCommon   File: AtomicBooleanDemo.java    License: Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 3
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);
}
 
Example 4
Source Project: bazel-buildfarm   File: Extract.java    License: Apache License 2.0 5 votes vote down vote up
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();
    }
  };
}