Pause Thread Using Sleep Method - Java Thread

Java examples for Thread:Thread Operation

Description

Pause Thread Using Sleep Method

Demo Code

 
public class Main {
 
        public static void main(String[] args) {
                try{
                       /*from  www  .  j  a  v  a 2 s  .c  o  m*/
                        for(int i=0; i< 5; i++){
                               
                                System.out.println(i);
                               
                                Thread.sleep(1000);
                        }
                }
                catch(InterruptedException ie){
                        System.out.println("Thread interrupted !" + ie);
                }
               
        }
}

Result


Related Tutorials