HOW TO USE JAVA TIMER
Java Timer tasks are the scheduled tasks for the program, they are intented to be executed on a specific interval of times or on a specific time such as this :
There is a Timer class that we will create and it will contain a class to be executed in a specific intervals.
Timer timer = new Timer();
timer.scheduleAtFixedRate(new Go(), 0,20000);
first we created timer and we attached a schedule that is 20000 ms will be 20 seconds to the Go class.
Go class is special because it is extends the TimerTask which will have a function called run()
public class Go extends TimerTask{
public void run(){
//This code will be run
}
}
also you can define a delay time before execute in schedule through this parameter
timer.scheduleAtFixedRate(new Go(),DELAY,20000);
No comments:
Post a Comment