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:Main.java
/** * Get a diff between two dates/*from w w w.j ava2 s .c o m*/ * * @param timeUnit the unit in which you want the diff * @return the diff value, in the provided unit */ private static long getDateDiff(long diffInMillis, TimeUnit timeUnit) { return timeUnit.convert(diffInMillis, TimeUnit.MILLISECONDS); }
From source file:io.anserini.index.IndexClueWeb09b.java
public static void main(String[] args) throws IOException, InterruptedException { IndexArgs indexArgs = new IndexArgs(); CmdLineParser parser = new CmdLineParser(indexArgs, ParserProperties.defaults().withUsageWidth(90)); try {/*from www . ja v a 2 s. c o m*/ parser.parseArgument(args); } catch (CmdLineException e) { System.err.println(e.getMessage()); parser.printUsage(System.err); System.err.println("Example: IndexClueWeb09b" + parser.printExample(OptionHandlerFilter.REQUIRED)); return; } final long start = System.nanoTime(); IndexClueWeb09b indexer = new IndexClueWeb09b(indexArgs.input, indexArgs.index); indexer.setPositions(indexArgs.positions); indexer.setOptimize(indexArgs.optimize); indexer.setDocLimit(indexArgs.doclimit); LOG.info("Index path: " + indexArgs.index); LOG.info("Threads: " + indexArgs.threads); LOG.info("Positions: " + indexArgs.positions); LOG.info("Optimize (merge segments): " + indexArgs.optimize); LOG.info("Doc limit: " + (indexArgs.doclimit == -1 ? "all docs" : "" + indexArgs.doclimit)); LOG.info("Indexer: start"); int numIndexed = indexer.indexWithThreads(indexArgs.threads); final long durationMillis = TimeUnit.MILLISECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS); LOG.info("Total " + numIndexed + " documents indexed in " + DurationFormatUtils.formatDuration(durationMillis, "HH:mm:ss")); }
From source file:Main.java
public static boolean await(CountDownLatch cl, long millseconds) { try {// w w w .java 2 s. c om return cl.await(millseconds, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { return false; } }
From source file:Main.java
/** * Waits till thread is in state./*from ww w. jav a 2s . co m*/ * * @param thread the tread to monitor * @param state the state to wait for * @throws InterruptedException if the calling thread gets interrupted */ public static void waitTillThreadInState(Thread thread, Thread.State state) throws InterruptedException { while (thread.getState() != state) { TimeUnit.MILLISECONDS.sleep(1L); } }
From source file:com.amazonaws.http.ConnectionManagerFactory.java
public static PoolingClientConnectionManager createPoolingClientConnManager(ClientConfiguration config, HttpParams httpClientParams) {// w w w . j ava 2 s . com PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager( SchemeRegistryFactory.createDefault(), config.getConnectionTTL(), TimeUnit.MILLISECONDS); connectionManager.setDefaultMaxPerRoute(config.getMaxConnections()); connectionManager.setMaxTotal(config.getMaxConnections()); if (config.useReaper()) { IdleConnectionReaper.registerConnectionManager(connectionManager); } return connectionManager; }
From source file:example.springdata.cassandra.util.CassandraSocket.java
/** * @param host must not be {@literal null} or empty. * @param port//from www . j a v a 2 s .c o m * @return {@literal true} if the TCP port accepts a connection. */ public static boolean isConnectable(String host, int port) { Assert.hasText(host, "Host must not be null or empty!"); try (Socket socket = new Socket()) { socket.setSoLinger(true, 0); socket.connect(new InetSocketAddress(host, port), (int) TimeUnit.MILLISECONDS.convert(10, TimeUnit.SECONDS)); return true; } catch (Exception e) { return false; } }
From source file:Main.java
public static void shutdownNow(ExecutorService exec) { if (exec != null) { List<Runnable> tasks = exec.shutdownNow(); if (tasks.size() == 0) { System.out.println(/*from ww w .j a v a2 s .c o m*/ "Runnable tasks outlived thread pool executor service [" + ", tasks=" + tasks + ']'); } try { exec.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { System.out.println( "Got interrupted while waiting for executor service to stop.[" + e.toString() + "]"); } } }
From source file:Main.java
/** * Runs and blocking waits for the given callable to finish for the given * time. Returns <code>null</code> if timeouts waiting for callable value. * // w ww . j a va 2 s . co m * @param millisTimeout * @param callable * @return */ public static <R> R runWithTimeout(long millisTimeout, Callable<R> callable) { ExecutorService singleThreadExecutor = Executors.newFixedThreadPool(1); Future<R> future = singleThreadExecutor.submit(callable); try { return future.get(millisTimeout, TimeUnit.MILLISECONDS); } catch (InterruptedException | ExecutionException | TimeoutException e) { } finally { singleThreadExecutor.shutdown(); } return null; }
From source file:com.amazonaws.services.dynamodbv2.http.ConnectionManagerFactory.java
public static PoolingClientConnectionManager createPoolingClientConnManager(ClientConfiguration config, HttpParams httpClientParams) {// w ww.j a v a 2s . co m PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager( SchemeRegistryFactory.createDefault(), config.getConnectionTTL(), TimeUnit.MILLISECONDS, new DelegatingDnsResolver(config.getDnsResolver())); connectionManager.setDefaultMaxPerRoute(config.getMaxConnections()); connectionManager.setMaxTotal(config.getMaxConnections()); if (config.useReaper()) { IdleConnectionReaper.registerConnectionManager(connectionManager); } return connectionManager; }
From source file:Main.java
public static String durationToFloat(long milliseconds) { long minute = TimeUnit.MILLISECONDS.toMinutes(milliseconds); long seconds = TimeUnit.MILLISECONDS.toSeconds(milliseconds) - TimeUnit.MINUTES.toSeconds(minute); if (seconds == 60) { minute = minute + 1;/* w w w .ja v a2 s . com*/ seconds = 0; } else { seconds = (100 * seconds) / 60; } return String.format("%d.%d", minute, seconds); }