Pause the execution : Sleep Pause « Thread « Java Tutorial






class Wait {
  public static void oneSec() {
    try {
      Thread.currentThread().sleep(1000);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }

  public static void manySec(long s) {
    try {
      Thread.currentThread().sleep(s * 1000);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }
}

public class Main{
  public static void main(String args[]) {
    Wait.oneSec();
    Wait.manySec(5);
  }
}








10.18.Sleep Pause
10.18.1.Pause the execution
10.18.2.Pausing the Current Thread: a thread can temporarily stop execution.
10.18.3.Add a delay
10.18.4.Pause the execution of a thread using sleep()