public
void sleep(long timeout) throws InterruptedException
Performs
a Thread.sleep using this time unit. Causes the current thread to
sleep.
Example
import java.util.concurrent.TimeUnit; public class TimeUnitEx { public static void main(String args[])throws Exception{ System.out.println("About to sleep for two minutes"); TimeUnit.MINUTES.sleep(2); System.out.println("2 Min Sleep finished"); } }
Output
About to sleep for two minutes 2 Min Sleep finished
TimeUnit.MINUTES.sleep(2)
: Causes the thread to sleep for 2 minutes
TimeUnit.SECONDS.sleep(10)
: Causes the thread to sleep for 10 seconds
TimeUnit.HOURS.sleep(10)
: Causes the thread to sleep for 10 hours
No comments:
Post a Comment