Example usage for java.util.concurrent TimeUnit MILLISECONDS

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

Introduction

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

Prototype

TimeUnit MILLISECONDS

To view the source code for java.util.concurrent TimeUnit MILLISECONDS.

Click Source Link

Document

Time unit representing one thousandth of a second.

Usage

From source file:Main.java

public static void await(CountDownLatch barrier, long timeoutMillis) {
    try {/* w ww . j a v a  2 s.  co  m*/
        barrier.await(timeoutMillis, TimeUnit.MILLISECONDS);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
}

From source file:Main.java

public static String getTimespentString(long millis) {

    if (millis == 0) {
        return "Undetermined";
    }/*from w ww . j  av a 2s .  c  om*/

    StringBuilder sb = new StringBuilder(64);

    if (millis < 0) {
        sb.append("-");
        millis *= -1;
    }

    long hours = TimeUnit.MILLISECONDS.toHours(millis);
    millis -= TimeUnit.HOURS.toMillis(hours);
    long minutes = TimeUnit.MILLISECONDS.toMinutes(millis);
    millis -= TimeUnit.MINUTES.toMillis(minutes);
    long seconds = TimeUnit.MILLISECONDS.toSeconds(millis);

    sb.append(hours);
    sb.append(":");

    if (minutes < 10) {
        sb.append("0");
    }
    sb.append(minutes);

    return (sb.toString());
}

From source file:Main.java

public static long getDaysDiff(long startTime, long endTime) {
    long msDiff;/*from   ww  w . j av  a2s  .  c  o m*/
    if (endTime > startTime) {
        msDiff = endTime - startTime;
    } else {
        msDiff = startTime - endTime;
    }
    // Log.e(TAG,"diff is  "+ daysDiff);
    return TimeUnit.MILLISECONDS.toDays(msDiff);
}

From source file:Main.java

public static ThreadPoolExecutor createThreadPool() {
    ThreadPoolExecutor pool = new ThreadPoolExecutor(NUM_PROCESSORS, NUM_PROCESSORS, 1000,
            TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
    return pool;/*from www  . ja va2  s.com*/
}

From source file:Main.java

/**
 * /* w  w  w  .j a  v  a  2  s  .  c  o  m*/
 */
protected static void decorateProperties(ThreadPoolExecutor executor, Properties properties) {
    if (executor != null) {
        if (properties != null) {
            properties.setProperty("thread-keep-alive-time",
                    Long.toString(executor.getKeepAliveTime(TimeUnit.MILLISECONDS)));

            properties.setProperty("thread-pool-size-largest", Integer.toString(executor.getLargestPoolSize()));

            properties.setProperty("thread-pool-size-minimum", Integer.toString(executor.getCorePoolSize()));

            properties.setProperty("thread-pool-size-maximum", Integer.toString(executor.getMaximumPoolSize()));

            properties.setProperty("thread-pool-size", Integer.toString(executor.getPoolSize()));

            properties.setProperty("runnable-completed-count", Long.toString(executor.getCompletedTaskCount()));

            properties.setProperty("runnable-active-count", Integer.toString(executor.getActiveCount()));

            properties.setProperty("queue-size", Integer.toString(executor.getQueue().size()));

            properties.setProperty("queue-capacity-remaining",
                    Integer.toString(executor.getQueue().remainingCapacity()));
        }
    }
}

From source file:Main.java

/**
 * millisecondsToHours/*from   w w  w .  jav  a2s  .  c  o m*/
 * Get the hh:mm value from milliseconds
 * @param millis the milliseconds value
 * @return a string with the time in hh:mm format
 */
public static String millisecondsToHours(long millis) {
    return String.format(Locale.getDefault(), "%02d:%02d", TimeUnit.MILLISECONDS.toHours(millis),
            TimeUnit.MILLISECONDS.toMinutes(millis) % TimeUnit.HOURS.toMinutes(1));
}

From source file:Main.java

public static long getDifferenceinMinutes(Date date1, Date date2) {
    System.out.println(date1.toString());

    System.out.println(date2.toString());

    if (date1 == null || date2 == null)
        return 0;

    long diff = date2.getTime() - date1.getTime();

    long diffMinutes = TimeUnit.MINUTES.convert(diff, TimeUnit.MILLISECONDS);

    return diffMinutes;
}

From source file:Main.java

/**
 * The number of days from today until the date passed in.
 *
 * @param date The date to count days until.
 * @return The number of days until the date.
 *//*from www. j a  v  a  2 s . c  o  m*/
public static long getNumDaysUntilDate(Date date) {
    long msDiff = date.getTime() - Calendar.getInstance().getTimeInMillis();
    return TimeUnit.MILLISECONDS.toDays(msDiff);
}

From source file:Main.java

public static ThreadPoolExecutor newFixedThreadPool(int corePoolSize, BlockingQueue<Runnable> queue) {
    return new ThreadPoolExecutor(corePoolSize, corePoolSize, 0, TimeUnit.MILLISECONDS, queue);
}

From source file:Main.java

/**
 * Convert a millisecond duration to a string format
 *
 * @param millis A duration to convert to a string form
 * @return A string of the form "X Days Y Hours Z Minutes A Seconds".
 *//*from  w w  w  .j a  v  a2s.  co m*/
public static String getDurationBreakdown(long millis) {
    if (millis < 0) {
        throw new IllegalArgumentException("Duration must be greater than zero!");
    }

    long days = TimeUnit.MILLISECONDS.toDays(millis);
    millis -= TimeUnit.DAYS.toMillis(days);
    long hours = TimeUnit.MILLISECONDS.toHours(millis);
    millis -= TimeUnit.HOURS.toMillis(hours);
    long minutes = TimeUnit.MILLISECONDS.toMinutes(millis);
    millis -= TimeUnit.MINUTES.toMillis(minutes);
    long seconds = TimeUnit.MILLISECONDS.toSeconds(millis);

    return (String.valueOf(days) + " Days " + hours + " Hours " + minutes + " Minutes " + seconds + " Seconds");
}