java wait 2 seconds code example
Example 1: java utils wait for seconds
try
{
Thread.sleep(1000);
}
catch(InterruptedException ex)
{
Thread.currentThread().interrupt();
}
Example 2: java delay
Syntax :
=========================================================
Thread.sleep(1000);
=========================================================
int i=0;
for(;;){
Thread.sleep(2000);
System.out.println(i++);
}
Example 3: java pause 1 second
try {
Thread.sleep(1000);
} catch (InterruptedException e) {e.printStackTrace();}
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
}
}, 1000);