Mega Code Archive

 
Categories / Java Tutorial / Thread
 

Pause the execution of a thread using sleep()

class Wait {   public static void bySeconds(long s) {     try {       Thread.currentThread().sleep(s * 1000);     } catch (InterruptedException e) {       e.printStackTrace();     }   } } public class Main {   public static void main(String args[]) {     System.out.println("Wait");     Wait.bySeconds(5);     System.out.println("Done");   } }