1try
2{
3 Thread.sleep(1000);
4}
5catch(InterruptedException ex)
6{
7 Thread.currentThread().interrupt();
8}
9
1Syntax :
2=========================================================
3 Thread.sleep(1000); // 1000 milliseconds.. |
4=========================================================
5int i=0;
6for(;;){
7 Thread.sleep(2000); // set time delay to 2 seconds..
8 System.out.println(i++); // output : every output will display after 2 seconds..
9}
1/** from: java.util.concurrent.TimeUnit **/
2
3// Sleep for 1 second
4TimeUnit.SECONDS.sleep(1);
5
6// Sleep for 1 minute
7TimeUnit.MINUTES.sleep(1);