Java Thread sleep

Introduction

A thread can be suspended using sleep() method:

public static void sleep(long millis) 
public static void sleep(long millis, int nanos) 
    

public class Main {
  public static void main(String args[]) {
    for (;;) {//from   w  w w  .  j  av a 2  s.  com
      System.out.println("Local date and time: " + new java.util.Date());
      try {
        Thread.sleep(4000);
      } catch (InterruptedException ie) {
      }
    }
  }
}



PreviousNext

Related