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
Source Project: qpid-jms File: ProducerAndConsumerBench.java License: Apache License 2.0 | 6 votes |
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 |
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
Source Project: DWSurvey File: FormAuthenticationWithLockFilter.java License: GNU Affero General Public License v3.0 | 5 votes |
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 |
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(); } }; }