Here is sample code example of Sleep Thread in Java.
In this example we have put Main thread in Sleep for 1 second.
/*
* Example of Thread Sleep method in Java
*/
public class SleepTest {
public static void main(String... args){
System.out.println(Thread.currentThread().getName() + " is going to sleep for 1 Second");
try {
Thread.currentThread().sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Main Thread is woken now");
}
}
Output:
main is going to sleep for 1 Second
Main Thread is woken now