I am translating some Javascript code into Java, and need to know how to do Timeouts in Java. How would I translate the following into Java?
var x = setTimeout(function(){ ... }, 2000);
clearTimeout(x);
Try out with java.util.Timer
You can schedule your task when the specified time is over or into a periodic interval. Use
myTimer.schedule(tt, 2000);
where tt is a TimerTask object from java.util.TimerTask (you have to implement the run() method, who will correspond to your "function(){ ... }" in javascript).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With