+ 1
How do you utilize timers in Java?
How does one create a java timer which functions similar to the setInterval() feature in javascript? I would to have example() called every 10 seconds until a while loop condition is satisfied in the calling method. Any suggestions?
3 odpowiedzi
+ 1
After researching the timer object, this is the answer I've come up with:
import java.util.Timer;
import java.util.TimerTask;
public class Example{
public static void main(String[]args){
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask(){
public void run(){
// Execute example code here
}
}, 0, 10000);
}
}
0
Timer t = new Timer();
I forget the parameters.. Google Java Timer()
0
if it doesn't work, it might need a thread