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}
1System.out.println("Hi");
2//Now it will pause
3try{
4 Thread.sleep(5000)//Time in milliseconds->5000==5 seconds
5 //^freezes whole program for amount of time
6 System.out.println("Hola");//Appears after 5 seconds
7}
8catch(InterruptedException e){
9 System.err.println(e.getMessage());
10}
1new java.util.Timer().schedule(
2 new java.util.TimerTask() {
3 @Override
4 public void run() {
5 // your code here
6 }
7 },
8 5000
9);