Thread Sleep In Java Example
Chapter:
Thread
Last Updated:
15-07-2016 13:50:38 UTC
Program:
/* ............... START ............... */
public class JavaThreadSleep {
public static void main(String[] args) {
try {
System.out.println("sleep for 10 seconds.");
Thread.sleep(10000);
// The "main" thread will sleep
System.out.println("woke up.");
} catch (InterruptedException e) {
System.out.println("interrupted.");
}
System.out.println("Exit");
}
}
/* ............... END ............... */
Output
sleep for 10 seconds.
woke up.
Exit
Notes:
-
The java.lang.Thread.sleep(long millis) method causes the currently executing thread to sleep for the specified number of millisecond.
- Syntax : public static void sleep(long millis) throws InterruptedException.
- millis is the length of time to sleep in milliseconds.
Tags
Thread Sleep, Java