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:com.cloudhopper.commons.io.demo.FileServerMain.java
public static void loadFilesFromDir(String dir, int threads) { ThreadPoolExecutor ex = new ThreadPoolExecutor(threads, threads, 5000l, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>()); ex.prestartAllCoreThreads();/*from w w w. j ava 2 s . c o m*/ IdGenerator idGen = new UUIDIdGenerator(); final FileStore store = new SimpleNIOFileStore(idGen, "/tmp/fileStore/"); final long start = System.currentTimeMillis(); int count = 0; Iterator<File> it = FileUtils.iterateFiles(new File(dir), null, true); while (it.hasNext()) { final File f = it.next(); final int num = count++; Runnable job = new Runnable() { @Override public void run() { try { RandomAccessFile randomAccessFile = new RandomAccessFile(f, "r"); FileChannel fileChannel = randomAccessFile.getChannel(); Id id = store.write(fileChannel); System.out.println("(" + num + ") Stored " + f.getPath() + " as " + id.getName() + " after " + (System.currentTimeMillis() - start) + "ms"); } catch (Exception e) { logger.error("", e); } } }; ex.execute(job); } }
From source file:com.bt.aloha.util.CollectionHelper.java
public static void destroy(ConcurrentMap<String, Map<String, Object>> transients, String classname) { log.debug(String.format("Destroy method called on collection: %s", classname)); for (Map<String, Object> element : transients.values()) { ScheduledFuture<?> future = (ScheduledFuture<?>) element.get("future"); if (future == null || future.isCancelled() || future.isDone()) continue; if (future.getDelay(TimeUnit.MILLISECONDS) > ONE_HUNDRED) { future.cancel(true);/* w ww . j a va 2 s. c om*/ continue; } int counter = 0; while (!future.isDone() && counter++ < THREE) { try { log.debug("Waiting for future to get done for some call..."); Thread.sleep(ONE_THOUSAND); } catch (InterruptedException e) { log.warn(e.getMessage()); continue; } } } }
From source file:org.apache.streams.elasticsearch.example.ElasticsearchDelete.java
private static ExecutorService newFixedThreadPoolWithQueueSize(int nThreads, int queueSize) { return new ThreadPoolExecutor(nThreads, nThreads, 5000L, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(queueSize, true), new ThreadPoolExecutor.CallerRunsPolicy()); }
From source file:com.alibaba.wasp.metrics.JmxCacheBuster.java
/** * For JMX to forget about all previously exported metrics. *//* www . j av a 2s . co m*/ public static void clearJmxCache() { // If there are more then 100 ms before the executor will run then // everything should be merged. if (fut == null || (!fut.isDone() && fut.getDelay(TimeUnit.MILLISECONDS) > 100)) return; synchronized (lock) { fut = MetricsExecutor.getExecutor().schedule(new JmxCacheBusterRunnable(), 5, TimeUnit.SECONDS); } }
From source file:com.googlecode.jcasockets.perf.Client.java
static void printStatisticsAsCSV(PrintStream printStream, ExecutionStatistics executionStatistics) { printStream.printf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n", executionStatistics.getBytesSent(), executionStatistics.getBytesReceived(), executionStatistics.getElapsed(TimeUnit.MILLISECONDS), executionStatistics.getMessagesSent(), executionStatistics.getMessagesReceived(), executionStatistics.getMinimumMessageSize(), executionStatistics.getMaximumMessageSize(), executionStatistics.getBytesSentPerSecond(), executionStatistics.getBytesReceivedPerSecond(), executionStatistics.getMessagesPerSecond()); }
From source file:Main.java
/** * Convert a millisecond duration to a string format * * @param millis// w ww .ja v a 2s . c o m * A duration to convert to a string form * @return A string of the form "X Days Y Hours Z Minutes A Seconds". */ public static String getDurationBreakdown(long millis, final boolean showMS) { if (millis <= 0) { return "-"; } final long days = TimeUnit.MILLISECONDS.toDays(millis); millis -= TimeUnit.DAYS.toMillis(days); final long hours = TimeUnit.MILLISECONDS.toHours(millis); millis -= TimeUnit.HOURS.toMillis(hours); final long minutes = TimeUnit.MILLISECONDS.toMinutes(millis); millis -= TimeUnit.MINUTES.toMillis(minutes); final long seconds = TimeUnit.MILLISECONDS.toSeconds(millis); millis -= TimeUnit.SECONDS.toMillis(seconds); final StringBuilder sb = new StringBuilder(); if (days > 0) { sb.append(days); sb.append("d "); } if (hours > 0) { sb.append(String.format("%02d", hours)); sb.append("h "); } if (minutes > 0) { sb.append(String.format("%02d", minutes)); sb.append("min "); } if (seconds > 0) { sb.append(String.format("%02d", seconds)); sb.append("s"); } if ((seconds <= 0) && (millis > 0) && showMS) { sb.append(String.format("%02d", millis)); sb.append("ms"); } return sb.toString(); }
From source file:OkHttpEngine.java
@Override public ResponseEntity<String> submit(JCurlRequestOptions requestOptions) throws Exception { OkHttpClient client = new OkHttpClient.Builder().connectTimeout(2000, TimeUnit.MILLISECONDS) .sslSocketFactory(SSLContext.getDefault().getSocketFactory()).followSslRedirects(true).build(); ResponseEntity<String> responseEntity = null; for (int i = 0; i < requestOptions.getCount(); i++) { final Request.Builder requestBuilder = new Request.Builder().url(requestOptions.getUrl()) .headers(Headers.of(requestOptions.getHeaderMap())).get(); Request request = requestBuilder.build(); System.out.println("\nSending 'GET' request to URL : " + requestOptions.getUrl()); Response response = client.newCall(request).execute(); int responseCode = response.code(); System.out.println("Response Code : " + responseCode); final InputStream is = response.body().byteStream(); String responseContent = IOUtils.toString(is); is.close();// w ww . ja v a 2s.c o m //print result System.out.println(responseContent); responseEntity = new ResponseEntity<String>(responseContent, HttpStatus.valueOf(responseCode)); } return responseEntity; }
From source file:de.codecentric.batch.metrics.ConsoleMetricsExporter.java
public ConsoleMetricsExporter(MetricRegistry metricRegistry) { reporter = ConsoleReporter.forRegistry(metricRegistry).convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS).build(); }
From source file:Main.java
public Main() { for (int i = 0; i < 10; i++) { final int c = i; submitTask(new Callable<Object>() { @Override/*from ww w . j a va 2 s . c om*/ public Object call() throws Exception { long t = System.currentTimeMillis(); try { Thread.sleep(2000); System.out.println("Task " + c + " done in " + (System.currentTimeMillis() - t) + "ms"); } catch (Exception e) { System.out .println("Task " + c + " aborted after " + (System.currentTimeMillis() - t) + "ms"); } return null; } }, 1000); } ex.shutdown(); try { ex.awaitTermination(100000, TimeUnit.MILLISECONDS); } catch (Exception e) { e.printStackTrace(); } }
From source file:edu.mum.service.impl.EventServiceImpl.java
@Override public void save(Event event) { List<EventRegister> eventRegisters = new ArrayList<>(); long duration = event.getEndTime().getTime() - event.getStartTime().getTime(); long diffInMins = TimeUnit.MILLISECONDS.toMinutes(duration); int defaultDuration = durationManagedBean.getDuration(); int slot = (int) (diffInMins / defaultDuration); Date date = event.getStartTime(); for (int i = 0; i < slot; i++) { EventRegister eventRegister = new EventRegister(); eventRegister.setStartTime(date); date = addMinutesToDate(defaultDuration, date); eventRegister.setEndTime(date);// w w w. j a v a2 s .c o m eventRegister.setEvent(event); eventRegisters.add(eventRegister); } event.setEventDetails(eventRegisters); eventsDao.update(event); }