List of usage examples for java.util.concurrent TimeUnit MILLISECONDS
TimeUnit MILLISECONDS
To view the source code for java.util.concurrent TimeUnit MILLISECONDS.
Click Source Link
From source file:io.anserini.search.SearchCollection.java
public static void main(String[] args) throws Exception { SearchArgs searchArgs = new SearchArgs(); CmdLineParser parser = new CmdLineParser(searchArgs, ParserProperties.defaults().withUsageWidth(90)); try {//from w w w .j a v a 2 s . co m parser.parseArgument(args); } catch (CmdLineException e) { System.err.println(e.getMessage()); parser.printUsage(System.err); System.err.println("Example: SearchCollection" + parser.printExample(OptionHandlerFilter.REQUIRED)); return; } final long start = System.nanoTime(); SearchCollection searcher = new SearchCollection(searchArgs); int numTopics = searcher.runTopics(); searcher.close(); final long durationMillis = TimeUnit.MILLISECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS); LOG.info("Total " + numTopics + " topics searched in " + DurationFormatUtils.formatDuration(durationMillis, "HH:mm:ss")); }
From source file:userinterface.CyberSecurity.ChartFactory.java
public static ChartPanel createChart(UserAccount account) { Map<String, LoginDetails> loginDetails = account.getLoginDetails(); DefaultCategoryDataset dataset1 = new DefaultCategoryDataset(); DefaultCategoryDataset dataset2 = new DefaultCategoryDataset(); Collection<LoginDetails> values = loginDetails.values(); for (LoginDetails details : values) { dataset1.addValue(TimeUnit.MILLISECONDS.toHours(details.getLogoutTime() - details.getLoginTime()), HOURS_WORKED_BY_USER, details.getLoginDate()); dataset2.addValue(2.5, MINIMUM_WORKING_HOURS, details.getLoginDate()); }/* w w w. j av a 2 s. c o m*/ dataset1.addValue(2, HOURS_WORKED_BY_USER, "4-19-2016"); dataset1.addValue(3, HOURS_WORKED_BY_USER, "4-20-2016"); dataset2.addValue(2.5, MINIMUM_WORKING_HOURS, "4-19-2016"); dataset2.addValue(2.5, MINIMUM_WORKING_HOURS, "4-20-2016"); final CategoryItemRenderer renderer = new BarRenderer(); final CategoryPlot plot = new CategoryPlot(); plot.setDataset(dataset1); plot.setRenderer(renderer); plot.setDomainAxis(new CategoryAxis("Date")); plot.setRangeAxis(new NumberAxis("Hours")); plot.setOrientation(PlotOrientation.VERTICAL); plot.setRangeGridlinesVisible(true); plot.setDomainGridlinesVisible(true); // now create the second dataset and renderer... final CategoryItemRenderer renderer2 = new LineAndShapeRenderer(); plot.setDataset(1, dataset2); plot.setRenderer(1, renderer2); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45); final JFreeChart chart = new JFreeChart(plot); chart.setTitle("Employee work hours"); chart.setBackgroundPaint(Color.WHITE); // add the chart to a panel... final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); return chartPanel; }
From source file:com.clustercontrol.jobmanagement.util.TimeToANYhourConverter.java
/** * ????/* ww w. j a va 2 s . com*/ * ???? * ??????????????? * + TimeUnit.MILLISECONDS.toSeconds(49999L) */ public static String toDiffTime(Long startMillis, Long endMillis) { if (startMillis == null || endMillis == null) { return Messages.getString(""); } if (startMillis > endMillis) { return Messages.getString(""); } long sessionFromTime = TimeUnit.MILLISECONDS.toSeconds(endMillis); long sessionTOTime = TimeUnit.MILLISECONDS.toSeconds(startMillis); long sessionTime = sessionFromTime - sessionTOTime; long oneSeconds = 1L; long oneMinutes = 60L; long oneHours = 60L; long basicSeconds = sessionTime / oneSeconds; long sessionMinutes = basicSeconds / oneMinutes; long sessionSeconds = basicSeconds % oneMinutes; long sessionHours = sessionMinutes / oneHours; long sessionMinutesRest = sessionMinutes % oneHours; String diffTime = String.format("%1$02d", sessionHours) + ":" + String.format("%1$02d", sessionMinutesRest) + ":" + String.format("%1$02d", sessionSeconds); return diffTime; }
From source file:info_teorija_1.Tests.java
public static void test(String fileIn, String fileOut, String fileRes) throws IOException { Stopwatch total = Stopwatch.createStarted(); for (int i = 2; i <= 16; i++) { File in = new File(fileIn); File out = new File(fileOut); File res = new File(fileRes); System.out.println("Testing with " + i); Encode.clear();//from w w w . j a v a 2 s . c o m Decode.clear(); HuffmanCode.clear(); Stopwatch encode = Stopwatch.createStarted(); Encode.encode(i, in, out); System.out.println("Encoding: " + encode.elapsed(TimeUnit.MILLISECONDS)); encode.stop(); Stopwatch decode = Stopwatch.createStarted(); Decode.decode(out, res); System.out.println("Decoding: " + decode.elapsed(TimeUnit.MILLISECONDS)); assertTrue(FileUtils.contentEquals(in, res)); System.out.println("completed"); out.delete(); res.delete(); } System.out.println("Total test: " + total.elapsed(TimeUnit.MILLISECONDS)); }
From source file:Main.java
/** * Await for condition, handling//from ww w. j av a 2s. c o m * <a href="http://errorprone.info/bugpattern/WaitNotInLoop">spurious wakeups</a>. * @param condition condition to await for * @param timeout the maximum time to wait in milliseconds * @return value from {@link Condition#await(long, TimeUnit)} */ public static boolean await(final Condition condition, final long timeout) throws InterruptedException { boolean awaited = false; long timeoutRemaining = timeout; long awaitStarted = System.currentTimeMillis(); while (!awaited && timeoutRemaining > 0) { awaited = condition.await(timeoutRemaining, TimeUnit.MILLISECONDS); timeoutRemaining -= System.currentTimeMillis() - awaitStarted; } return awaited; }
From source file:org.z.global.util.TimeValue.java
public static TimeValue timeValueMillis(long millis) { return new TimeValue(millis, TimeUnit.MILLISECONDS); }
From source file:com.ning.metrics.collector.util.Stats.java
/** * Create a time window stats object./*from w w w .jav a 2 s .co m*/ * * @param period length of the time window * @param unit unit of period * @return stats */ public static Stats timeWindow(long period, TimeUnit unit) { long millis = TimeUnit.MILLISECONDS.convert(period, unit); return new Stats(new SynchronizedTimeWindowStatistics(millis), new SynchronizedTimeWindowStatistics(millis), WindowType.TIME, 0, period, unit); }
From source file:com.hazelcast.simulator.worker.metronome.SimpleMetronome.java
/** * Creates a {@link Metronome} instance with a fixed millisecond interval. * * @param intervalMs wait interval in milliseconds * @return a {@link Metronome} instance/*from w w w. j av a2 s .co m*/ */ public static Metronome withFixedIntervalMs(int intervalMs) { if (intervalMs == 0) { return EMPTY_METRONOME; } return new SimpleMetronome(TimeUnit.MILLISECONDS.toNanos(intervalMs)); }
From source file:it.geosolutions.tools.io.file.FileGarbageCollector.java
/** * Return a initialized instance of this singleton * @return initialized instance of this singleton * @throws InterruptedException - if Unable to get the lock *//*www . j a va 2s.c o m*/ public static FileCleaningTracker getFileCleaningTracker() { if (singleton == null) { try { lock.tryLock(LOCK_WAIT_TIME, TimeUnit.MILLISECONDS); build(singleton); } catch (InterruptedException ie) { StringBuilder message = new StringBuilder("Unable to get lock on the "); message.append(FileGarbageCollector.class.toString()); message.append(" message: " + ie.getLocalizedMessage()); if (LOGGER.isErrorEnabled()) { LOGGER.error(message.toString()); } } finally { lock.unlock(); } } return singleton; }
From source file:gobblin.data.management.retention.sql.SqlUdfs.java
private static long date_diff(long timestamp1, long timestamp2, String unitString) { try {/*from ww w .jav a 2 s . co m*/ TimeUnit unit = TimeUnit.valueOf(TimeUnit.class, StringUtils.upperCase(unitString)); return unit.convert(timestamp1 - timestamp2, TimeUnit.MILLISECONDS); } catch (IllegalArgumentException e) { log.error("Valid input for unitString is java.util.concurrent.TimeUnit", e); } return 0l; }