Real'sHowTo AddThis Feed Button
Custom Search

Pause the executionTag(s): Thread


public 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 TestWait {
  public static void main(String args[]) {
     System.out.println("Wait one second");
     Wait.oneSec();
     System.out.println("Done\nWait five seconds");
     Wait.manySec(5);
     System.out.println("Done");
     }
}

blog comments powered by Disqus


If you find this article useful, consider making a small donation
to show your support for this Web site and its content.

Written and compiled by Réal Gagnon ©1998-2013
[ home ]