Here you can find the source of sleep(long duration, TimeUnit timeUnit)
Parameter | Description |
---|---|
duration | a parameter |
timeUnit | a parameter |
public static void sleep(long duration, TimeUnit timeUnit)
//package com.java2s; //License from project: Open Source License import java.util.concurrent.TimeUnit; public class Main { /**/*from w ww . j av a 2 s .c om*/ * A convenience version of Thread.sleep that uses TimeUnits instead of raw * milliseconds and swallows interrupted exceptions * * @param duration * @param timeUnit */ public static void sleep(long duration, TimeUnit timeUnit) { try { Thread.sleep(toMillis(duration, timeUnit)); } catch (InterruptedException ex) { System.out.println("sleep interrupted: " + ex.getMessage()); } } public static long toMillis(long duration, TimeUnit timeUnit) { return TimeUnit.MILLISECONDS.convert(duration, timeUnit); } }