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.willwinder.universalgcodesender.utils.ThreadHelperTest.java
@Test public void waitUntilWhenFalseShouldTimeout() { StopWatch stopWatch = new StopWatch(); stopWatch.start();//from w w w. java 2s . com try { ThreadHelper.waitUntil(() -> false, 200, TimeUnit.MILLISECONDS); } catch (TimeoutException ignored) { // Never mind } stopWatch.stop(); assertTrue(stopWatch.getTime() >= 200); }
From source file:com.nesscomputing.quartz.QuartzJobStatistics.java
QuartzJobStatistics(final MetricsRegistry metricsRegistry, final JobKey jobKey) { final String keyName = jobKey.getName() + (StringUtils.isBlank(jobKey.getGroup()) || JobKey.DEFAULT_GROUP.equals(jobKey.getGroup()) ? "" : "-" + jobKey.getGroup()); this.runtime = metricsRegistry.newTimer(new MetricName("ness.quartz.job", "statistics", keyName), TimeUnit.MILLISECONDS, TimeUnit.MINUTES); }
From source file:com.qpark.eip.core.spring.statistics.impl.AppUserStatisticsChannelAdapter.java
/** * @param millis/*from w ww.j ava 2 s .c o m*/ * @return the duration in 000:00:00.000 format. */ static String getDuration(final long millis) { String hmss = String.format("%03d:%02d:%02d.%03d", TimeUnit.MILLISECONDS.toHours(millis), TimeUnit.MILLISECONDS.toMinutes(millis) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millis)), TimeUnit.MILLISECONDS.toSeconds(millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)), TimeUnit.MILLISECONDS.toMillis(millis) - TimeUnit.SECONDS.toMillis(TimeUnit.MILLISECONDS.toSeconds(millis))); return hmss; }
From source file:org.zenoss.zep.dao.impl.ElapsedTime.java
public static String formatElapsed(final long elapsedMillis) { final long hr = TimeUnit.MILLISECONDS.toHours(elapsedMillis); final long min = TimeUnit.MILLISECONDS.toMinutes(elapsedMillis - TimeUnit.HOURS.toMillis(hr)); final long sec = TimeUnit.MILLISECONDS .toSeconds(elapsedMillis - TimeUnit.HOURS.toMillis(hr) - TimeUnit.MINUTES.toMillis(min)); final long ms = TimeUnit.MILLISECONDS.toMillis(elapsedMillis - TimeUnit.HOURS.toMillis(hr) - TimeUnit.MINUTES.toMillis(min) - TimeUnit.SECONDS.toMillis(sec)); return String.format("%02dh:%02dm:%02d.%03ds", hr, min, sec, ms); }
From source file:localworker.LocalWorker.java
@SuppressWarnings("unchecked") @Override/*from www.j a va2 s. com*/ public void run() { JSONParser parser = new JSONParser(); JSONObject json; String task_id = null; String task; try { while (true) { //waiting up to 100ms for an element to become available. String messageBody = jobQ.poll(100, TimeUnit.MILLISECONDS); if (messageBody != null) { json = (JSONObject) parser.parse(messageBody); task_id = json.get("task_id").toString(); task = json.get("task").toString(); Thread.sleep(Long.parseLong(task)); JSONObject result = new JSONObject(); result.put("task_id", task_id); result.put("result", "0"); respQ.put(result.toString()); //System.out.println(Thread.currentThread().getName()+" sleep done!"); } } } catch (Exception e) { JSONObject result = new JSONObject(); result.put("task_id", task_id); result.put("result", "1"); try { respQ.put(result.toString()); } catch (InterruptedException e1) { e1.printStackTrace(); } } }
From source file:Main.java
public void runTest() throws Exception { ThreadPoolExecutor tp = new ThreadPoolExecutor(1, 1, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>()); tp.setRejectedExecutionHandler(/*from w w w . ja v a 2s .c o m*/ (Runnable r, ThreadPoolExecutor executor) -> System.out.println("Task rejected: " + r)); Semaphore oneTaskDone = new Semaphore(0); tp.execute(() -> { System.out.println("Sleeping"); try { Thread.sleep(300); } catch (Exception e) { e.printStackTrace(); } System.out.println("Done sleeping"); oneTaskDone.release(); }); tp.execute(new Runnable() { @Override public void run() { System.out.println("Never happends"); } @Override public String toString() { return "Rejected Runnable"; } }); oneTaskDone.acquire(); tp.execute(() -> System.out.println("Running")); tp.shutdown(); tp.awaitTermination(100, TimeUnit.MILLISECONDS); System.out.println("Finished"); }
From source file:net.easymfne.factionsdb.Util.java
/** * Convert a time in milliseconds to a user-friendly String format. * //from ww w . j a v a 2 s .co m * @param time * Number of milliseconds * @return User-friendly String */ public static String generateTimeString(long time) { List<String> timeStrings = new ArrayList<String>(); long d = TimeUnit.MILLISECONDS.toDays(time); time -= TimeUnit.DAYS.toMillis(d); long h = TimeUnit.MILLISECONDS.toHours(time); time -= TimeUnit.HOURS.toMillis(h); long m = TimeUnit.MILLISECONDS.toMinutes(time); time -= TimeUnit.MINUTES.toMillis(m); long s = TimeUnit.MILLISECONDS.toSeconds(time); if (d > 0) { timeStrings.add(d + (d == 1 ? " day" : " days")); } if (h > 0) { timeStrings.add(h + (h == 1 ? " hour" : " hours")); } if (m > 0) { timeStrings.add(m + (m == 1 ? " minute" : " minutes")); } if (s > 0 || timeStrings.size() < 1) { timeStrings.add(s + (s == 1 ? " second" : " seconds")); } return StringUtils.join(timeStrings, ", "); }
From source file:ch.ralscha.extdirectspring_itest.SimpleService.java
@ExtDirectMethod(value = ExtDirectMethodType.SIMPLE_NAMED, group = "itest_simple", streamResponse = true) public String echo(String userId, @RequestParam(defaultValue = "10") int logLevel) { // Simulate some work try {/*from w w w .ja v a 2s . c o m*/ TimeUnit.MILLISECONDS.sleep(200); } catch (InterruptedException e) { // do nothing here } return String.format("UserId: %s LogLevel: %d", userId, logLevel); }
From source file:com.android.volley.mock.WaitableQueue.java
public void waitUntilEmpty(long timeoutMillis) throws TimeoutException, InterruptedException { add(mStopRequest);//from ww w. j a v a 2s . co m if (!mStopEvent.tryAcquire(timeoutMillis, TimeUnit.MILLISECONDS)) { throw new TimeoutException(); } }
From source file:com.hortonworks.streamline.streams.runtime.storm.bolt.StreamlineWindowedBolt.java
/** Supports configuring windowing related settings via Streamline GUI. * Note: This will be kept Streamline specific and wont be migrated to Storm. * *///from w w w .j av a2 s . c o m public void withWindowConfig(Window windowConfig) throws IOException { if (windowConfig.getWindowLength() instanceof Window.Duration) { Duration windowLength = new Duration(((Window.Duration) windowConfig.getWindowLength()).getDurationMs(), TimeUnit.MILLISECONDS); if (windowConfig.getSlidingInterval() instanceof Window.Duration) { Duration slidingInterval = new Duration( ((Window.Duration) windowConfig.getSlidingInterval()).getDurationMs(), TimeUnit.MILLISECONDS); withWindow(windowLength, slidingInterval); } else if (windowConfig.getSlidingInterval() instanceof Window.Count) { Count slidingInterval = new Count(((Window.Count) windowConfig.getSlidingInterval()).getCount()); withWindow(windowLength, slidingInterval); } else { withWindow(windowLength); } } else if (windowConfig.getWindowLength() instanceof Window.Count) { Count windowLength = new Count(((Window.Count) windowConfig.getWindowLength()).getCount()); if (windowConfig.getSlidingInterval() instanceof Window.Duration) { Duration slidingInterval = new Duration( ((Window.Duration) windowConfig.getWindowLength()).getDurationMs(), TimeUnit.MILLISECONDS); withWindow(windowLength, slidingInterval); } else if (windowConfig.getSlidingInterval() instanceof Window.Count) { Count slidingInterval = new Count(((Window.Count) windowConfig.getWindowLength()).getCount()); withWindow(windowLength, slidingInterval); } else { withWindow(windowLength); } } if (windowConfig.getLagMs() != 0) { withLag(new Duration(windowConfig.getLagMs(), TimeUnit.MILLISECONDS)); } if (!StringUtils.isEmpty(windowConfig.getTsField())) { withTimestampExtractor(new StreamlineTimestampExtractor(windowConfig.getTsField())); } }