Example usage for java.util.concurrent TimeUnit toMillis

List of usage examples for java.util.concurrent TimeUnit toMillis

Introduction

In this page you can find the example usage for java.util.concurrent TimeUnit toMillis.

Prototype

public long toMillis(long duration) 

Source Link

Document

Equivalent to #convert(long,TimeUnit) MILLISECONDS.convert(duration, this) .

Usage

From source file:Main.java

public static void main(String[] args) {
    TimeUnit tu = TimeUnit.DAYS;

    System.out.println(tu.toDays(1));
    System.out.println(tu.toHours(1));
    System.out.println(tu.toMillis(1));

}

From source file:Main.java

public static void sleep(long timeout, TimeUnit unit) {
    sleep(unit.toMillis(timeout));
}

From source file:Main.java

public static void sleep(long duration, TimeUnit unit) {
    try {//w w w  .  ja v a 2s .c  o  m
        Thread.sleep(unit.toMillis(duration));
    } catch (Exception ignored) {
    }
}

From source file:Main.java

public static void sleep(long duration, TimeUnit unit) {
    try {/*from w  w w. j av  a 2  s  .c om*/
        Thread.sleep(unit.toMillis(duration));
    } catch (InterruptedException var4) {
        Thread.currentThread().interrupt();
    }

}

From source file:Main.java

public static void sleep(long duration, TimeUnit unit) {
    try {//  w  w w.ja v  a  2s . c  o  m
        Thread.sleep(unit.toMillis(duration));
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
}

From source file:Main.java

private static boolean isWithin(final long millis, final long span, final TimeUnit unit) {
    return System.currentTimeMillis() - millis <= unit.toMillis(span);
}

From source file:Main.java

public static void reallySleep(TimeUnit unit, long sleepTime) {
    reallySleep(unit.toMillis(sleepTime));
}

From source file:Main.java

/**
 * Get the expected value of {@link System#currentTimeMillis} after the given period of time has passed.
 * Negative values for {@code time} return a time from the past.  While the notes about overflow in
 * {@link #futureTimeNanos} apply in principal here, an overflow of the 64-bit millisecond clock happens
 * once every 600 million years, with the year 1970 at 0.  So it's safe to use simple operators to make
 * comparisons between the current time and this method's result.
 *//* www  .  java2  s  .  c om*/
public static long futureTimeMillis(long time, TimeUnit unit) {
    return System.currentTimeMillis() + unit.toMillis(time);
}

From source file:Main.java

public static void awaitForTermination(List<Thread> threads, long timeout, TimeUnit timeUnit) {
    try {//from  w  w  w. j  a  v a2 s.c om
        long finishTime = System.currentTimeMillis() + timeUnit.toMillis(timeout);
        for (Thread t : threads) {
            long now = System.currentTimeMillis();
            if (now > finishTime) {
                throw new IllegalStateException("failed to stop all threads");
            } else {
                t.join(finishTime - now);
                if (t.isAlive()) {
                    throw new IllegalStateException("failed to stop all threads");
                }
            }
        }
    } catch (InterruptedException e) {
        throw new IllegalStateException(e);
    }
}

From source file:com.sonatype.nexus.perftest.RequestRate.java

private static int parseRate(String value) {
    StringTokenizer st = new StringTokenizer(value, " /");
    int time = Integer.parseInt(st.nextToken());
    TimeUnit unit = TimeUnit.valueOf(st.nextToken() + "S");
    return (int) (unit.toMillis(1) / time);
}