@Override public Void call() throws Exception { ZooKeeper zooKeeper = null; try { zooKeeper = new ZooKeeper(host, timeout, EmptyWatcher.instance); Stat exists = zooKeeper.exists(znode, false); StopWatch stopwatch = new StopWatch(); stopwatch.start(); zooKeeper.getData(znode, false, exists); stopwatch.stop(); sink.publishReadTiming(znode, host, stopwatch.getTime()); } catch (KeeperException | InterruptedException e) { sink.publishReadFailure(znode, host); } finally { if (zooKeeper != null) { zooKeeper.close(); } } return null; } }
@Test public void testGetStartTime() { final long beforeStopWatch = System.currentTimeMillis(); final StopWatch watch = new StopWatch(); try { watch.getStartTime(); fail("Calling getStartTime on an unstarted StopWatch should throw an exception"); } catch (final IllegalStateException expected) { // expected } watch.start(); try { watch.getStartTime(); assertTrue(watch.getStartTime() >= beforeStopWatch); } catch (final IllegalStateException ex) { fail("Start time should be available: " + ex.getMessage()); } watch.reset(); try { watch.getStartTime(); fail("Calling getStartTime on a reset, but unstarted StopWatch should throw an exception"); } catch (final IllegalStateException expected) { // expected } }
@Test public void testStopWatchSplit() { final StopWatch watch = new StopWatch(); watch.start(); try { Thread.sleep(550); } catch (final InterruptedException ex) { } watch.split(); final long splitTime = watch.getSplitTime(); final String splitStr = watch.toSplitString(); try { Thread.sleep(550); } catch (final InterruptedException ex) { } watch.unsplit(); try { Thread.sleep(550); } catch (final InterruptedException ex) { } watch.stop(); final long totalTime = watch.getTime(); assertEquals("Formatted split string not the correct length", splitStr.length(), 12); assertTrue(splitTime >= 500); assertTrue(splitTime < 700); assertTrue(totalTime >= 1500); assertTrue(totalTime < 1900); }
@Override public void start(Stage primaryStage) { this.primaryStage = primaryStage; injector = initInjector(); Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionLogger()); initSejda(); cleanIfRequired(); primaryStage.setScene(initScene()); primaryStage.getIcons().addAll(injector.instancesOfType(Image.class)); primaryStage.setTitle(injector.instance(Pdfsam.class).name()); primaryStage.setOnCloseRequest(e -> Platform.exit()); requestPremiumModulesDescriptionIfRequired(); initWindowsStatusController(primaryStage); initDialogsOwner(primaryStage); initActiveModule(); loadWorkspaceIfRequired(); initOpenButtons(); primaryStage.show(); requestCheckForUpdateIfRequired(); requestLatestNewsIfRequired(); eventStudio().addAnnotatedListeners(this); closeSplash(); STOPWATCH.stop(); LOG.info(DefaultI18nContext.getInstance().i18n("Started in {0}", DurationFormatUtils.formatDurationWords(STOPWATCH.getTime(), true, true))); new InputPdfArgumentsController().accept(rawParameters); }
@Test public void testSampleIterator() throws CatalogException, SolrServerException, IOException { MongoDBAdaptorFactory factory = new MongoDBAdaptorFactory(catalogManager.getConfiguration()); SampleDBAdaptor sampleDBAdaptor = factory.getCatalogSampleDBAdaptor(); QueryOptions queryOptions = new QueryOptions(); queryOptions.add(QueryOptions.INCLUDE, Arrays.asList(SampleDBAdaptor.QueryParams.ID.key(), SampleDBAdaptor.QueryParams.UID.key(), SampleDBAdaptor.QueryParams.INDIVIDUAL.key() + ".id")); //queryOptions.add("nativeQuery", true); queryOptions.add("lazy", false); DBIterator<Sample> sampleDBIterator = sampleDBAdaptor.iterator(new Query(), queryOptions); int i = 0; StopWatch stopWatch = StopWatch.createStarted(); while (sampleDBIterator.hasNext()) { Sample sample = sampleDBIterator.next(); i++; if (i % 10000 == 0) { System.out.println("i: " + i + "; time: " + stopWatch.getTime(TimeUnit.MILLISECONDS)); stopWatch.reset(); stopWatch.start(); } // System.out.println(sample); // if (sample.getAttributes() != null && sample.getAttributes().containsKey("individual")) { // System.out.println(sample.getAttributes().get("individual")); // } } }
dfs.recoverLease(partPath); boolean isclosed = dfs.isFileClosed(partPath); StopWatch sw = new StopWatch(); sw.start(); while (!isclosed) { if (sw.getTime() > asyncTimeout) { break; StopWatch sw = new StopWatch(); sw.start(); long newLen = fs.getFileStatus(partPath).getLen(); while (newLen != validLength) { if (sw.getTime() > asyncTimeout) { break;
@Test public void testBooleanStates() { final StopWatch watch = new StopWatch(); assertFalse(watch.isStarted()); assertFalse(watch.isSuspended()); assertTrue(watch.isStopped()); watch.start(); assertTrue(watch.isStarted()); assertFalse(watch.isSuspended()); assertFalse(watch.isStopped()); watch.suspend(); assertTrue(watch.isStarted()); assertTrue(watch.isSuspended()); assertFalse(watch.isStopped()); watch.stop(); assertFalse(watch.isStarted()); assertFalse(watch.isSuspended()); assertTrue(watch.isStopped()); }
@Test public void testBadStates() { final StopWatch watch = new StopWatch(); try { watch.stop(); fail("Calling stop on an unstarted StopWatch should throw an exception. "); } catch (final IllegalStateException ise) { watch.stop(); fail("Calling stop on an unstarted StopWatch should throw an exception. "); } catch (final IllegalStateException ise) { watch.suspend(); fail("Calling suspend on an unstarted StopWatch should throw an exception. "); } catch (final IllegalStateException ise) { watch.split(); fail("Calling split on a non-running StopWatch should throw an exception. "); } catch (final IllegalStateException ise) { watch.unsplit(); fail("Calling unsplit on an unsplit StopWatch should throw an exception. "); } catch (final IllegalStateException ise) { watch.resume(); fail("Calling resume on an unsuspended StopWatch should throw an exception. "); } catch (final IllegalStateException ise) { watch.start();
protected void skipOrUpdateBinaryClassifier(int component, int label, MultiLabelClfDataSet activeDataSet, double[] activeGammas, double totalWeight){ StopWatch stopWatch = new StopWatch(); stopWatch.start(); cbm.binaryClassifiers[component][label] = new PriorProbClassifier(probs); sb.append(", skip, use prior = ").append(smoothedPositiveProb); sb.append(", time spent = ").append(stopWatch.toString()); if (logger.isDebugEnabled()){ logger.debug(sb.toString());
public void run(Runnable command, String timeReportPrefix) { if (reportTimeEnabled.get()) { StopWatch stopWatch = stopWatchLocal.get(); stopWatch.reset(); stopWatch.start(); command.run(); long nanoTime = stopWatch.getNanoTime(); if (nanoTime > minimumNanoTimeToReport.get()) LogTools.info(timeReportPrefix + Conversions.nanosecondsToSeconds(nanoTime)); } else command.run(); } }
/** * <p> * Gets a summary of the time that the stopwatch recorded as a string. * </p> * * <p> * The format used is ISO 8601-like, <i>hours</i>:<i>minutes</i>:<i>seconds</i>.<i>milliseconds</i>. * </p> * * @return the time as a String */ @Override public String toString() { return DurationFormatUtils.formatDurationHMS(getTime()); }
@Override public void onCompleted() { timer.stop(); latch.countDown(); }
@Override public void init() { STOPWATCH.start(); rawParameters = getParameters().getRaw(); verboseIfRequired(); startLogAppender(); System.setProperty(PDDocumentHandler.SAMBOX_USE_ASYNC_WRITER, Boolean.TRUE.toString()); System.setProperty(Sejda.UNETHICAL_READ_PROPERTY_NAME, Boolean.TRUE.toString()); LOG.info("Starting PDFsam"); clean = rawParameters.contains("--clean") || rawParameters.contains("-clean") || rawParameters.contains("-c"); cleanUserContextIfNeeded(userContext); String localeString = userContext.getLocale(); if (isNotBlank(localeString)) { eventStudio().broadcast(new SetLocaleEvent(localeString)); } String defaultworkingPath = userContext.getDefaultWorkingPath(); if (isNotBlank(defaultworkingPath)) { try { if (Files.isDirectory(Paths.get(defaultworkingPath))) { eventStudio().broadcast(new SetLatestDirectoryEvent(new File(defaultworkingPath))); } } catch (InvalidPathException e) { LOG.warn("Unable to set initial directory, default path is invalid.", e); } } }
org.apache.commons.lang3.time.StopWatch sw = new StopWatch(); sw.start(); Thread.sleep(1000 * 4); sw.stop(); System.out.println("Apache StopWatch : "+ millisToShortDHMS(sw.getTime()) );
@Override public void lifeCycleStopping(final LifeCycle event) { timer.reset(); log("Stopping Jetty..."); }