Bootstrap FreeKB - Java - Pause execution using sleep
Java - Pause execution using sleep

Updated:   |  Java articles

Here is an example of how to use Thread.sleep can be used to pause the execution of tasks. The value is in milliseconds, so 1000 milliseconds would be a 1 second pause. Notice also that throws InterruptedException is required. In this example, there will be a 1 second pause between printing Hello and World.

public class Main {
  public static void main(String[] args) throws InterruptedException { 
    System.out.println("Hello");
    Thread.sleep(1000);
    System.out.println("World");
  }
}

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter a83cc1 in the box below so that we can be sure you are a human.