List of usage examples for java.util.concurrent.atomic AtomicInteger AtomicInteger
public AtomicInteger(int initialValue)
From source file:jenkins.plugins.itemstorage.s3.S3UploadAllCallable.java
/** * Upload from slave/*from ww w.ja v a 2 s.co m*/ */ @Override public Integer invoke(final TransferManager transferManager, File base, VirtualChannel channel) throws IOException, InterruptedException { if (!base.exists()) return 0; final AtomicInteger count = new AtomicInteger(0); final Uploads uploads = new Uploads(); final Map<String, S3ObjectSummary> summaries = lookupExistingCacheEntries( transferManager.getAmazonS3Client()); // Find files to upload that match scan scanner.scan(base, new FileVisitor() { @Override public void visit(File f, String relativePath) throws IOException { if (f.isFile()) { String key = pathPrefix + "/" + relativePath; S3ObjectSummary summary = summaries.get(key); if (summary == null || f.lastModified() > summary.getLastModified().getTime()) { final ObjectMetadata metadata = buildMetadata(f); uploads.startUploading(transferManager, f, IOUtils.toBufferedInputStream(FileUtils.openInputStream(f)), new Destination(bucketName, key), metadata); if (uploads.count() > 20) { waitForUploads(count, uploads); } } } } }); // Wait for each file to complete before returning waitForUploads(count, uploads); return uploads.count(); }
From source file:com.aol.advertising.qiao.util.CommonUtils.java
public static ScheduledThreadPoolExecutor createScheduledThreadPoolExecutor(final int poolSz, final String threadName) { return new ScheduledThreadPoolExecutor(poolSz, new ThreadFactory() { private AtomicInteger threadNum = new AtomicInteger(0); @Override//from w w w . ja v a 2s . c om public Thread newThread(Runnable r) { if (poolSz == 1) return new Thread(r, threadName); else return new Thread(r, threadName + threadNum.incrementAndGet()); } }); }
From source file:org.jtheque.core.LifeCycleTest.java
@Test @DirtiesContext//from w w w.java 2 s .c o m public void titleListener() { final AtomicInteger titleCounter = new AtomicInteger(0); lifeCycle.addTitleListener(new TitleListener() { @Override public void titleUpdated(String title) { titleCounter.incrementAndGet(); } }); lifeCycle.refreshTitle(); assertEquals(1, titleCounter.intValue()); }
From source file:com.futureplatforms.kirin.extensions.networking.NetworkingBackend.java
public NetworkingBackend(Context context, IKirinExtensionHelper kirinHelper, String saveFileLocation) { super(context, "Networking", kirinHelper); mContext = context;/*from w w w .j a va 2 s . co m*/ String packageName = mContext.getPackageName(); String sdCardPrefix = Environment.getExternalStorageDirectory().getPath(); String path = sdCardPrefix + MessageFormat.format("/Android/data/{0}/files", packageName); if (!path.endsWith("/")) { path += "/"; } mFileUtils = new SDCardFileUtils(path); mDownloadingCount = new AtomicInteger(0); }
From source file:strat.mining.multipool.stats.service.impl.RequestStatsLoggingServiceImpl.java
@Override public void currencyTicker(String exchangePlace, String currencyCode) { nbCurrencyTicker.incrementAndGet();/*from w w w . j av a2 s . co m*/ Map<String, AtomicInteger> currencies = currencyTickerRequest.get(exchangePlace); if (currencies == null) { currencies = Collections.synchronizedMap(new HashMap<String, AtomicInteger>()); currencyTickerRequest.put(exchangePlace, currencies); } AtomicInteger currencyCounter = currencies.get(currencyCode); if (currencyCounter == null) { currencyCounter = new AtomicInteger(0); currencies.put(currencyCode, currencyCounter); } currencyCounter.incrementAndGet(); }
From source file:com.greplin.zookeeper.RobustZooKeeper.java
public RobustZooKeeper(String ensembleAddresses) throws IOException { this.reconnectCount = new AtomicInteger(-1); // start at -1 so that the initial connection doesn't count this.shutdown = new AtomicBoolean(false); this.reconnectLock = new ReentrantLock(); this.ensembleAddress = ensembleAddresses; this.client = null; clientNumber = INSTANCE_COUNTER.incrementAndGet(); }
From source file:ufo.remote.calls.benchmark.client.caller.vertx.VertxClusterTester.java
@Override protected void startTest(final TesterResult result) { EventBus bus = vertx.eventBus();//from ww w . ja va2 s.com CountDownLatch latch = new CountDownLatch(result.totalCalls); AtomicInteger failures = new AtomicInteger(0); for (int i = 0; i < result.totalCalls; i++) { bus.send("echo", result.message, (AsyncResult<Message<String>> response) -> { if (response.failed()) { failures.incrementAndGet(); } if (logger.isDebugEnabled()) { logger.debug("Received [{}]", response.result().body()); } latch.countDown(); }); } try { latch.await(); } catch (InterruptedException e) { throw new RuntimeException(e); } result.failures = failures.get(); }
From source file:com.alibaba.dubbo.demo.consumer.DemoAction.java
public void start() throws Exception { int threads = 100; final DescriptiveStatistics stats = new SynchronizedDescriptiveStatistics(); DubboBenchmark.BenchmarkMessage msg = prepareArgs(); final byte[] msgBytes = msg.toByteArray(); int n = 1000000; final CountDownLatch latch = new CountDownLatch(n); ExecutorService es = Executors.newFixedThreadPool(threads); final AtomicInteger trans = new AtomicInteger(0); final AtomicInteger transOK = new AtomicInteger(0); long start = System.currentTimeMillis(); for (int i = 0; i < n; i++) { es.submit(() -> {//from www . j ava2s. c o m try { long t = System.currentTimeMillis(); DubboBenchmark.BenchmarkMessage m = testSay(msgBytes); t = System.currentTimeMillis() - t; stats.addValue(t); trans.incrementAndGet(); if (m != null && m.getField1().equals("OK")) { transOK.incrementAndGet(); } } catch (InterruptedException e) { e.printStackTrace(); } finally { latch.countDown(); } }); } latch.await(); start = System.currentTimeMillis() - start; System.out.printf("sent requests : %d\n", n); System.out.printf("received requests : %d\n", trans.get()); System.out.printf("received requests_OK : %d\n", transOK.get()); System.out.printf("throughput (TPS) : %d\n", n * 1000 / start); System.out.printf("mean: %f\n", stats.getMean()); System.out.printf("median: %f\n", stats.getPercentile(50)); System.out.printf("max: %f\n", stats.getMax()); System.out.printf("min: %f\n", stats.getMin()); System.out.printf("99P: %f\n", stats.getPercentile(90)); }
From source file:eu.stratosphere.pact.runtime.iterative.io.InterruptingMutableObjectIterator.java
public InterruptingMutableObjectIterator(MutableObjectIterator<E> delegate, int numberOfEventsUntilInterrupt, String name, Terminable owningIterativeTask, int gateIndex) { Preconditions.checkArgument(numberOfEventsUntilInterrupt > 0); this.delegate = delegate; this.numberOfEventsUntilInterrupt = numberOfEventsUntilInterrupt; // this.name = name; this.owningIterativeTask = owningIterativeTask; // this.gateIndex = gateIndex; endOfSuperstepEventCounter = new AtomicInteger(0); terminationEventCounter = new AtomicInteger(0); }
From source file:de.tudarmstadt.ukp.dkpro.core.norvig.NorvigSpellingAlgorithm.java
/** * Read words from the given reader and count their occurrences. * * @param aReader/*from ww w . j a va 2 s . com*/ * the reader. * @throws IOException * if the words cannot be read. */ public void train(Reader aReader) throws IOException { BufferedReader in = new BufferedReader(aReader); String line = in.readLine(); while (line != null) { Matcher m = WORD_PATTERN.matcher(line.toLowerCase()); while (m.find()) { String word = m.group(); AtomicInteger count = nWords.get(word); if (count == null) { count = new AtomicInteger(0); nWords.put(word, count); } count.incrementAndGet(); } line = in.readLine(); } }