delay to executes a function or specified piece of code in java
/**
* @author lautturi.com
* Java example:
*/
import java.util.*;
public class Lautturi {
public static void setTimeout(Runnable runnable, int delay){
new Thread(() -> {
try {
Thread.sleep(delay);
runnable.run();
}
catch (Exception e){
System.err.println(e);
}
}).start();
}
public static void main(String[] args){
setTimeout(() -> System.out.println("test"), 3000); // wait for 3 seconds to perform task
}
}Sourwww:ec.lautturi.com