/** * Returns the number of millis since the last call to <tt>reset</tt> or <tt>start</tt>. * * @return returns the number of milliseconds since the start of this watch. */ public long elapsedMillis() { return elapsed(TimeUnit.MILLISECONDS, false); }
/** * Determines if the duration of the operation is longer than its timeout * * @return <tt>true</tt> if the duration of the operation is longer than its timeout, <tt>false</tt> otherwise */ public boolean isOvertime() { return w.elapsed(TimeUnit.SECONDS, false) > timeout.getSeconds(); }
/** * Returns the formatted duration. * <p> * This method tries to generate a string which is as short as possible. Therefore, if the duration is * less than one microsecond, the number of nanoseconds is returned. If the duration is less than one millisecond, * the number of microseconds (rounded) is returned. Otherwise, the value is rounded to milliseconds and returned * as * formatted by {@link NLS#convertDuration(long)}. * * @param reset determines if the watch should be reset, after the duration has be computed. * @return a string representing the duration since the last call to <tt>reset</tt> or <tt>start</tt>. */ public String duration(boolean reset) { long elapsed = elapsed(TimeUnit.NANOSECONDS, reset); if (elapsed <= 1000) { return elapsed + " ns"; } elapsed = elapsed / 1000; if (elapsed <= 1000) { return elapsed + " us"; } return NLS.convertDuration(elapsed / 1000); }
private void executeTask(final TimedTask task) { tasks.executor(TIMER) .dropOnOverload(() -> Exceptions.handle() .to(LOG) .withSystemErrorMessage( "Dropping timer task '%s' (%s) due to system overload!", task, task.getClass()) .handle()) .start(() -> { try { Watch w = Watch.start(); task.runTimer(); if (w.elapsed(TimeUnit.SECONDS, false) > 1) { LOG.WARN("TimedTask '%s' (%s) took over a second to complete! " + "Consider executing the work in a separate executor!", task, task.getClass()); } } catch (Exception t) { Exceptions.handle(LOG, t); } }); }