java make method wait code example
Example 1: java delay
Syntax :
=========================================================
Thread.sleep(1000);
=========================================================
int i=0;
for(;;){
Thread.sleep(2000);
System.out.println(i++);
}
Example 2: 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);
Example 3: wait method in java
java.lang.Object.wait() causes current thread to wait until another thread
invokes the notify() method or the notifyAll() method for this object.