List of usage examples for java.util.concurrent.atomic AtomicInteger getAndIncrement
public final int getAndIncrement()
From source file:com.linkedin.pinot.tools.perf.QueryRunner.java
private static void executeQueryInMultiThreads(PerfBenchmarkDriver driver, String query, AtomicInteger numQueriesExecuted, AtomicLong totalBrokerTime, AtomicLong totalClientTime, List<Statistics> statisticsList) throws Exception { JSONObject response = driver.postQuery(query); numQueriesExecuted.getAndIncrement(); long brokerTime = response.getLong("timeUsedMs"); totalBrokerTime.getAndAdd(brokerTime); long clientTime = response.getLong("totalTime"); totalClientTime.getAndAdd(clientTime); statisticsList.get(0).addValue(clientTime); }
From source file:org.apache.jackrabbit.oak.run.DataStoreCheckCommand.java
private static void retrieveBlobReferences(GarbageCollectableBlobStore blobStore, BlobReferenceRetriever marker, File marked) throws IOException { final BufferedWriter writer = Files.newWriter(marked, Charsets.UTF_8); final AtomicInteger count = new AtomicInteger(); boolean threw = true; try {//from w ww. j a v a2s .c o m final Joiner delimJoiner = Joiner.on(DELIM).skipNulls(); final GarbageCollectableBlobStore finalBlobStore = blobStore; System.out.println("Starting dump of blob references"); Stopwatch watch = createStarted(); marker.collectReferences(new ReferenceCollector() { @Override public void addReference(String blobId, String nodeId) { try { Iterator<String> idIter = finalBlobStore.resolveChunks(blobId); while (idIter.hasNext()) { String id = delimJoiner.join(idIter.next(), nodeId); count.getAndIncrement(); writeAsLine(writer, id, true); } } catch (Exception e) { throw new RuntimeException("Error in retrieving references", e); } } }); writer.flush(); sort(marked, new Comparator<String>() { @Override public int compare(String s1, String s2) { return s1.split(DELIM)[0].compareTo(s2.split(DELIM)[0]); } }); System.out.println(count.get() + " blob references found"); System.out.println("Finished in " + watch.elapsed(TimeUnit.SECONDS) + " seconds"); threw = false; } finally { close(writer, threw); } }
From source file:cz.pichlik.goodsentiment.common.CSVReader.java
public void readLines(RowProcessor processor) { ArrayList<String> val = new ArrayList<>(); AtomicInteger counter = new AtomicInteger(0); csvParser.forEach((r) -> {// w ww . j a v a 2 s. c o m try { r.forEach((s) -> val.add(s)); processor.accept(val, counter.getAndIncrement()); } finally { val.clear(); } }); }
From source file:com.github.cbismuth.fdupes.io.PathOrganizer.java
private void onNoTimestampPath(final Path destination, final PathElement pathElement, final AtomicInteger counter) { final Path path = pathElement.getPath(); final String baseName = FilenameUtils.getBaseName(path.toString()); final int count = counter.getAndIncrement(); final String extension = FilenameUtils.getExtension(path.toString()); final String newName = String.format("%s-%d.%s", baseName, count, extension); final Path sibling = path.resolveSibling(newName); try {//ww w .j a va2 s . c om FileUtils.moveFile(path.toFile(), sibling.toFile()); FileUtils.moveFileToDirectory(sibling.toFile(), Paths.get(destination.toString(), "misc").toFile(), true); } catch (final IOException e) { LOGGER.error(e.getMessage()); } }
From source file:org.deeplearning4j.examples.multigpu.w2vsentiment.DataSetsBuilder.java
protected void saveDatasets(DataSetIterator iterator, String dir) { AtomicInteger counter = new AtomicInteger(0); new File(dir).mkdirs(); while (iterator.hasNext()) { String path = FilenameUtils.concat(dir, "dataset-" + (counter.getAndIncrement()) + ".bin"); iterator.next().save(new File(path)); if (counter.get() % 500 == 0) log.info("{} datasets saved so far...", counter.get()); }/*from w w w . jav a 2 s.com*/ }
From source file:org.aesh.terminal.telnet.TelnetTermTest.java
@Test public void testSizeHandler() throws Exception { final CountDownLatch latch1 = new CountDownLatch(1); final CountDownLatch latch2 = new CountDownLatch(1); server.start(() -> {// w w w . j a v a 2s. com final AtomicInteger count = new AtomicInteger(); return new TelnetTtyConnection(false, false, StandardCharsets.UTF_8, conn -> { conn.setSizeHandler(size -> { switch (count.getAndIncrement()) { case 0: assertEquals(20, size.getWidth()); assertEquals(10, size.getHeight()); latch1.countDown(); break; case 1: assertEquals(80, size.getWidth()); assertEquals(24, size.getHeight()); latch2.countDown(); break; case 2: assertEquals(180, size.getWidth()); assertEquals(160, size.getHeight()); testComplete(); break; default: fail("Was not expecting that"); } }); }); }); WindowSizeOptionHandler optionHandler = new WindowSizeOptionHandler(20, 10, false, false, true, false); client.setOptionHandler(optionHandler); client.connect("localhost", 4000); latch1.await(30, TimeUnit.SECONDS); client.writeDirectAndFlush(new byte[] { TelnetConnection.BYTE_IAC, TelnetConnection.BYTE_SB, 31, 0, 80, 0, 24, TelnetConnection.BYTE_IAC, TelnetConnection.BYTE_SE }); latch2.await(30, TimeUnit.SECONDS); client.writeDirectAndFlush(new byte[] { TelnetConnection.BYTE_IAC, TelnetConnection.BYTE_SB, 31, 0, (byte) 180, 0, (byte) 160, TelnetConnection.BYTE_IAC, TelnetConnection.BYTE_SE }); await(); }
From source file:org.apache.camel.idea.completion.extension.YamlPropertyPlaceholdersSmartCompletion.java
/** * Flat the List to string array and build the {@link CompletionResultSet} *//*from ww w. j a v a 2 s. c o m*/ private void buildResultSetForList(CompletionResultSet resultSet, VirtualFile virtualFile, String keyStr, List<?> propertyList) { final AtomicInteger count = new AtomicInteger(0); propertyList.forEach(e -> { if (e instanceof String) { String flatKeyStr = String.format("%s[%s]", keyStr, count.getAndIncrement()); buildResultSet(resultSet, virtualFile, flatKeyStr, String.valueOf(e)); } else if (e instanceof List) { buildResultSetForList(resultSet, virtualFile, keyStr, (List<?>) e); } else if (e instanceof LinkedHashMap) { buildResultSetForLinkedHashMap(resultSet, virtualFile, keyStr, propertyList); } }); }
From source file:org.diorite.impl.world.tick.TickGroups.java
@Override public synchronized void doTick(final int tps) { if (this.groups.isEmpty()) { if (!CoreMain.isClient()) { SpammyError.err(/* ww w. j a v a 2 s . c om*/ "There is no tick groups, server don't have anything to do. Do you have any worlds?", 10, key); } return; } if (this.groups.size() == 1) { /** * TODO count time of execution and split if needed. */ try { this.groups.iterator().next().doTick(tps); } catch (final Throwable throwable) { throwable.printStackTrace(); } return; } final AtomicInteger i = new AtomicInteger(0); final ForkJoinPool pool = new ForkJoinPool(this.groups.size(), p -> new NamedForkJoinWorkerThread(p, i.getAndIncrement()), (t, e) -> { // TODO: maybe add some pretty error priting System.err.println("Error in tick thread: " + t.getName()); e.printStackTrace(); }, false); /** * TODO count time of execution for all groups. * if any group is creating lags, try split it. (should not count single-time lags?) * if two grups can be join, try join them. */ final CountDownLatch latch = new CountDownLatch(this.groups.size()); for (final Iterator<TickGroupImpl> it = this.groups.iterator(); it.hasNext();) { final TickGroupImpl tickGroup = it.next(); if (tickGroup.isEmpty()) { it.remove(); latch.countDown(); continue; } pool.submit(() -> { try { tickGroup.doTick(tps); this.core.runScheduler(false); this.core.runSync(); } finally { latch.countDown(); } }); } try { latch.await(); } catch (final InterruptedException e) { e.printStackTrace(); } }
From source file:com.appleframework.monitor.service.AlertService.java
protected boolean isNeedNotify(Alert alert) { if (alert == null) return false; String key = alert.getProjectName() + "_" + alert.getTitle(); AtomicInteger init = new AtomicInteger(0); AtomicInteger times = notifyTimes.putIfAbsent(key, init); if (times == null) times = init;/*from w w w. ja v a2 s. c om*/ logger.debug("{} notify times ={}", key, times.get()); return times.getAndIncrement() < limitTimes; }
From source file:com.cloudera.oryx.app.als.FeatureVectorsTest.java
@Test public void testConcurrent() throws Exception { FeatureVectors fv = new FeatureVectors(); AtomicInteger counter = new AtomicInteger(); int numWorkers = 16; int numIterations = 10000; ExecUtils.doInParallel(numWorkers, i -> { for (int j = 0; j < numIterations; j++) { int c = counter.getAndIncrement(); fv.setVector(Integer.toString(c), new float[] { c }); }/*from w ww . ja v a 2s .c o m*/ }); assertEquals((long) numIterations * numWorkers, fv.size()); assertEquals((long) numIterations * numWorkers, counter.get()); ExecUtils.doInParallel(numWorkers, i -> { for (int j = 0; j < numIterations; j++) { fv.removeVector(Integer.toString(counter.decrementAndGet())); } }); assertEquals(0, fv.size()); }