Tabnine Logo
TimeUnit
Code IndexAdd Tabnine to your IDE (free)

How to use
TimeUnit
in
java.util.concurrent

Best Java code snippets using java.util.concurrent.TimeUnit (Showing top 20 results out of 46,827)

origin: spring-projects/spring-framework

/**
 * Specify the delay for the initial execution. It will be evaluated in
 * terms of this trigger's {@link TimeUnit}. If no time unit was explicitly
 * provided upon instantiation, the default is milliseconds.
 */
public void setInitialDelay(long initialDelay) {
  this.initialDelay = this.timeUnit.toMillis(initialDelay);
}
origin: square/retrofit

/** The network round trip delay. */
public long delay(TimeUnit unit) {
 return MILLISECONDS.convert(delayMs, unit);
}
origin: ReactiveX/RxJava

/**
 * Creates a new TestScheduler with the specified initial virtual time.
 *
 * @param delayTime
 *          the point in time to move the Scheduler's clock to
 * @param unit
 *          the units of time that {@code delayTime} is expressed in
 */
public TestScheduler(long delayTime, TimeUnit unit) {
  time = unit.toNanos(delayTime);
}
origin: stackoverflow.com

 String.format("%d min, %d sec", 
  TimeUnit.MILLISECONDS.toMinutes(millis),
  TimeUnit.MILLISECONDS.toSeconds(millis) - 
  TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis))
);
origin: stackoverflow.com

 String.format("%02d:%02d:%02d", 
TimeUnit.MILLISECONDS.toHours(millis),
TimeUnit.MILLISECONDS.toMinutes(millis) -  
TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millis)), // The change is in this line
TimeUnit.MILLISECONDS.toSeconds(millis) - 
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)));
origin: square/picasso

String logId() {
 long delta = System.nanoTime() - started;
 if (delta > TOO_LONG_LOG) {
  return plainId() + '+' + TimeUnit.NANOSECONDS.toSeconds(delta) + 's';
 }
 return plainId() + '+' + TimeUnit.NANOSECONDS.toMillis(delta) + "ms";
}
origin: crossoverJie/JCSprout

@Override
public String run() throws Exception {
  LOGGER.info("orderName=[{}]", orderName);
  TimeUnit.MILLISECONDS.sleep(100);
  return "OrderName=" + orderName;
}
origin: spring-projects/spring-framework

/**
 * Add a "stale-if-error" directive.
 * <p>This directive indicates that when an error is encountered, a cached stale response
 * MAY be used to satisfy the request, regardless of other freshness information.
 * @param staleIfError the maximum time the response should be used when errors are encountered
 * @param unit the time unit of the {@code staleIfError} argument
 * @return {@code this}, to facilitate method chaining
 * @see <a href="https://tools.ietf.org/html/rfc5861#section-4">rfc5861 section 4</a>
 */
public CacheControl staleIfError(long staleIfError, TimeUnit unit) {
  this.staleIfError = unit.toSeconds(staleIfError);
  return this;
}
origin: ReactiveX/RxJava

@NonNull
@Override
public Disposable schedule(@NonNull final Runnable action, final long delayTime, @NonNull final TimeUnit delayUnit) {
  TimeUnit common = delayUnit.compareTo(unit) < 0 ? delayUnit : unit;
  long t = common.convert(delayTime, delayUnit) + common.convert(delay, unit);
  return actualInner.schedule(action, t, common);
}
origin: crossoverJie/JCSprout

@Override
public String run() throws Exception {
  LOGGER.info("userName=[{}]", userName);
  TimeUnit.MILLISECONDS.sleep(100);
  return "userName=" + userName;
}
origin: spring-projects/spring-framework

/**
 * Add an "s-maxage" directive.
 * <p>This directive indicates that, in shared caches, the maximum age specified
 * by this directive overrides the maximum age specified by other directives.
 * @param sMaxAge the maximum time the response should be cached
 * @param unit the time unit of the {@code sMaxAge} argument
 * @return {@code this}, to facilitate method chaining
 * @see <a href="https://tools.ietf.org/html/rfc7234#section-5.2.2.9">rfc7234 section 5.2.2.9</a>
 */
public CacheControl sMaxAge(long sMaxAge, TimeUnit unit) {
  this.sMaxAge = unit.toSeconds(sMaxAge);
  return this;
}
origin: ReactiveX/RxJava

@NonNull
@Override
public Disposable schedule(@NonNull final Runnable action, final long delayTime, @NonNull final TimeUnit delayUnit) {
  TimeUnit common = delayUnit.compareTo(unit) < 0 ? delayUnit : unit;
  long t = common.convert(delayTime, delayUnit) + common.convert(delay, unit);
  return actualInner.schedule(action, t, common);
}
origin: stackoverflow.com

 public static void main(String[] args) throws ParseException {
  long millis = 3600000;
  String hms = String.format("%02d:%02d:%02d", 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)));
  System.out.println(hms);
}
origin: stackoverflow.com

 String.format("%02d min, %02d sec", 
  TimeUnit.MILLISECONDS.toMinutes(millis),
  TimeUnit.MILLISECONDS.toSeconds(millis) - 
  TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis))
);
origin: jenkinsci/jenkins

/**
 * Controls the time out of monitoring.
 */
protected long getMonitoringTimeOut() {
  return TimeUnit.SECONDS.toMillis(30);
}
origin: square/okhttp

public long getHeadersDelay(TimeUnit unit) {
 return unit.convert(headersDelayAmount, headersDelayUnit);
}
origin: google/guava

/**
 * Returns unit.toNanos(time), additionally ensuring the returned value is not at risk of
 * overflowing or underflowing, by bounding the value between 0 and (Long.MAX_VALUE / 4) * 3.
 * Actually waiting for more than 219 years is not supported!
 */
private static long toSafeNanos(long time, TimeUnit unit) {
 long timeoutNanos = unit.toNanos(time);
 return (timeoutNanos <= 0L)
   ? 0L
   : (timeoutNanos > (Long.MAX_VALUE / 4) * 3) ? (Long.MAX_VALUE / 4) * 3 : timeoutNanos;
}
origin: ctripcorp/apollo

 @Override
 public void run() {
  if (longPollingInitialDelayInMills > 0) {
   try {
    logger.debug("Long polling will start in {} ms.", longPollingInitialDelayInMills);
    TimeUnit.MILLISECONDS.sleep(longPollingInitialDelayInMills);
   } catch (InterruptedException e) {
    //ignore
   }
  }
  doLongPollingRefresh(appId, cluster, dataCenter);
 }
});
origin: spring-projects/spring-framework

/**
 * Add a "stale-while-revalidate" directive.
 * <p>This directive indicates that caches MAY serve the response in which it
 * appears after it becomes stale, up to the indicated number of seconds.
 * If a cached response is served stale due to the presence of this extension,
 * the cache SHOULD attempt to revalidate it while still serving stale responses
 * (i.e. without blocking).
 * @param staleWhileRevalidate the maximum time the response should be used while being revalidated
 * @param unit the time unit of the {@code staleWhileRevalidate} argument
 * @return {@code this}, to facilitate method chaining
 * @see <a href="https://tools.ietf.org/html/rfc5861#section-3">rfc5861 section 3</a>
 */
public CacheControl staleWhileRevalidate(long staleWhileRevalidate, TimeUnit unit) {
  this.staleWhileRevalidate = unit.toSeconds(staleWhileRevalidate);
  return this;
}
origin: square/retrofit

/** Set the network round trip delay. */
public void setDelay(long amount, TimeUnit unit) {
 if (amount < 0) {
  throw new IllegalArgumentException("Amount must be positive value.");
 }
 this.delayMs = unit.toMillis(amount);
}
java.util.concurrentTimeUnit

Javadoc

A TimeUnit represents time durations at a given unit of granularity and provides utility methods to convert across units, and to perform timing and delay operations in these units. A TimeUnit does not maintain time information, but only helps organize and use time representations that may be maintained separately across various contexts. A nanosecond is defined as one thousandth of a microsecond, a microsecond as one thousandth of a millisecond, a millisecond as one thousandth of a second, a minute as sixty seconds, an hour as sixty minutes, and a day as twenty four hours.

A TimeUnit is mainly used to inform time-based methods how a given timing parameter should be interpreted. For example, the following code will timeout in 50 milliseconds if the java.util.concurrent.locks.Lock is not available:

  
Lock lock = ...;
while this code will timeout in 50 seconds:
  
Lock lock = ...;
Note however, that there is no guarantee that a particular timeout implementation will be able to notice the passage of time at the same granularity as the given TimeUnit.

Most used methods

  • toMillis
    Equivalent to MILLISECONDS.convert(duration, this).
  • convert
  • toNanos
    Equivalent to NANOSECONDS.convert(duration, this).
  • sleep
    Performs a Thread#sleep(long,int) using this time unit. This is a convenience method that converts t
  • toSeconds
    Equivalent to SECONDS.convert(duration, this).
  • toMinutes
    Equivalent to MINUTES.convert(duration, this).
  • toMicros
    Equivalent to MICROSECONDS.convert(duration, this).
  • toDays
    Equivalent to DAYS.convert(duration, this).
  • valueOf
  • toHours
    Equivalent to HOURS.convert(duration, this).
  • toString
  • name
  • toString,
  • name,
  • timedWait,
  • hashCode,
  • timedJoin,
  • values,
  • equals,
  • ordinal,
  • compareTo,
  • excessNanos

Popular in Java

  • Reading from database using SQL prepared statement
  • requestLocationUpdates (LocationManager)
  • getSystemService (Context)
  • putExtra (Intent)
  • ConnectException (java.net)
    A ConnectException is thrown if a connection cannot be established to a remote host on a specific po
  • ConcurrentHashMap (java.util.concurrent)
    A plug-in replacement for JDK1.5 java.util.concurrent.ConcurrentHashMap. This version is based on or
  • Executors (java.util.concurrent)
    Factory and utility methods for Executor, ExecutorService, ScheduledExecutorService, ThreadFactory,
  • Collectors (java.util.stream)
  • JTextField (javax.swing)
  • Get (org.apache.hadoop.hbase.client)
    Used to perform Get operations on a single row. To get everything for a row, instantiate a Get objec
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now