List of usage examples for java.util.concurrent.atomic AtomicLong AtomicLong
public AtomicLong(long initialValue)
From source file:com.alibaba.rocketmq.example.operation.Consumer.java
public static void main(String[] args) throws InterruptedException, MQClientException { CommandLine commandLine = buildCommandline(args); if (commandLine != null) { String group = commandLine.getOptionValue('g'); String topic = commandLine.getOptionValue('t'); String subscription = commandLine.getOptionValue('s'); final String returnFailedHalf = commandLine.getOptionValue('f'); DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(group); consumer.setInstanceName(Long.toString(System.currentTimeMillis())); consumer.subscribe(topic, subscription); consumer.registerMessageListener(new MessageListenerConcurrently() { AtomicLong consumeTimes = new AtomicLong(0); @Override/* w w w . ja va2 s . c o m*/ public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext context) { long currentTimes = this.consumeTimes.incrementAndGet(); System.out.printf("%-8d %s\n", currentTimes, msgs); if (Boolean.parseBoolean(returnFailedHalf)) { if ((currentTimes % 2) == 0) { return ConsumeConcurrentlyStatus.RECONSUME_LATER; } } return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; } }); consumer.start(); System.out.println("Consumer Started."); } }
From source file:alluxio.cli.MiniBenchmark.java
/** * @param args there are no arguments needed * @throws Exception if error occurs during tests *//*from w w w . j a v a 2 s. c om*/ public static void main(String[] args) throws Exception { if (!parseInputArgs(args)) { usage(); System.exit(-1); } if (sHelp) { usage(); System.exit(0); } CommonUtils.warmUpLoop(); for (int i = 0; i < sIterations; ++i) { final AtomicInteger count = new AtomicInteger(0); final CyclicBarrier barrier = new CyclicBarrier(sConcurrency); ExecutorService executorService = Executors.newFixedThreadPool(sConcurrency); final AtomicLong runtime = new AtomicLong(0); for (int j = 0; j < sConcurrency; ++j) { switch (sType) { case READ: executorService.submit(new Runnable() { @Override public void run() { try { readFile(barrier, runtime, count.addAndGet(1)); } catch (Exception e) { LOG.error("Failed to read file.", e); System.exit(-1); } } }); break; case WRITE: executorService.submit(new Runnable() { @Override public void run() { try { writeFile(barrier, runtime, count.addAndGet(1)); } catch (Exception e) { LOG.error("Failed to write file.", e); System.exit(-1); } } }); break; default: throw new RuntimeException("Unsupported type."); } } executorService.shutdown(); Preconditions.checkState(executorService.awaitTermination(1, TimeUnit.HOURS)); double time = runtime.get() * 1.0 / sConcurrency / Constants.SECOND_NANO; System.out.printf("Iteration: %d; Duration: %f seconds; Aggregated throughput: %f GB/second.%n", i, time, sConcurrency * 1.0 * sFileSize / time / Constants.GB); } }
From source file:io.covert.dns.collection.ResolverThread.java
public static void main(String[] args) throws Exception { ConcurrentLinkedQueue<DnsRequest> inQueue = new ConcurrentLinkedQueue<DnsRequest>(); AtomicLong inQueueSize = new AtomicLong(0); ConcurrentLinkedQueue<Pair<Record, Message>> outQueue = new ConcurrentLinkedQueue<Pair<Record, Message>>(); String[] nameservers = new String[] { "8.8.8.8" }; inQueue.add(new DnsRequest("www6.google.com.", Type.AAAA, DClass.IN)); inQueue.add(new DnsRequest("ipv6.google.com.", Type.AAAA, DClass.IN)); inQueue.add(new DnsRequest("gmail.com.", Type.AAAA, DClass.IN)); inQueueSize.incrementAndGet();/*from ww w.j a v a 2 s . c o m*/ inQueueSize.incrementAndGet(); inQueueSize.incrementAndGet(); ResolverThread res = new ResolverThread(inQueue, inQueueSize, outQueue, nameservers, 5); res.start(); res.stopRunning(); res.join(); Pair<Record, Message> result = outQueue.remove(); System.out.println(result); result = outQueue.remove(); System.out.println(result); result = outQueue.remove(); System.out.println(result); }
From source file:Main.java
public static void addLong(ConcurrentMap<String, AtomicLong> map, String key, long delta) { map.putIfAbsent(key, new AtomicLong(0)); map.get(key).getAndAdd(delta);//w ww . jav a 2 s . c o m }
From source file:Main.java
public static void setLong(ConcurrentMap<String, AtomicLong> map, String key, long newValue) { map.putIfAbsent(key, new AtomicLong(0)); map.get(key).getAndSet(newValue);/*w w w.ja v a 2 s .c om*/ }
From source file:org.stem.streaming.AbstractSession.java
protected AbstractSession() { sessionId = UUID.randomUUID(); completed = new AtomicLong(-1); total = new AtomicLong(-1); }
From source file:org.stem.streaming.DiskMovement.java
public DiskMovement() { completed = new AtomicLong(-1); total = new AtomicLong(-1); }
From source file:io.kazuki.v0.store.journal.PartitionInfoImpl.java
public PartitionInfoImpl(@JsonProperty("partitionId") String partitionId, @JsonProperty("minId") long minId, @JsonProperty("maxId") long maxId, @JsonProperty("size") long size, @JsonProperty("closed") boolean closed) { this.partitionId = partitionId; this.minId = minId; this.maxId = new AtomicLong(maxId); this.size = new AtomicLong(size); this.closed = new AtomicBoolean(closed); }
From source file:com.demandware.vulnapp.challenge.impl.RNGChallenge.java
protected RNGChallenge(String name) { super(name); this.seed = new AtomicLong(System.currentTimeMillis()); beginSchedule(); }
From source file:com.espertech.esper.multithread.TestMTInsertIntoTimerConcurrency.java
public void testRun() throws Exception { idCounter = new AtomicLong(0); executorService = Executors.newCachedThreadPool(); noActionUpdateListener = new NoActionUpdateListener(); Configuration epConfig = new Configuration(); epConfig.addEventType(SupportBean.class); epConfig.getEngineDefaults().getThreading() .setInsertIntoDispatchLocking(ConfigurationEngineDefaults.Threading.Locking.SUSPEND); final EPServiceProvider epServiceProvider = EPServiceProviderManager.getDefaultProvider(epConfig); epServiceProvider.initialize();//from w w w. j av a 2s .c o m epAdministrator = epServiceProvider.getEPAdministrator(); epRuntime = epServiceProvider.getEPRuntime(); epAdministrator.startAllStatements(); String epl = "insert into Stream1 select count(*) as cnt from SupportBean.win:time(7 sec)"; createEPL(epl, noActionUpdateListener); epl = epl + " output every 10 seconds"; createEPL(epl, noActionUpdateListener); SendEventRunnable sendTickEventRunnable = new SendEventRunnable(10000); start(sendTickEventRunnable, 4); // Adjust here for long-running test Thread.sleep(3000); executorService.shutdown(); executorService.awaitTermination(1, TimeUnit.SECONDS); }