java wait milliseconds code example

Example 1: java utils wait for seconds

try        
{
    Thread.sleep(1000);
} 
catch(InterruptedException ex) 
{
    Thread.currentThread().interrupt();
}

Example 2: java pause 1 second

//deprecated in main thread:
try {
  Thread.sleep(1000);//time is in ms (1000 ms = 1 second)
} catch (InterruptedException e) {e.printStackTrace();}

//please use bellow instead:
Timer timer = new Timer();
timer.schedule(new TimerTask() {
  
  public void run() {
    //what you want to do
  }
}, 1000);//wait 1000ms before doing the action

Tags:

Dart Example