Timer execute same time every day
Hi all,
I want to create a task that will get executed the same time every day.
So I am using the timer class java.util.timer and the scheduleAtFixedRate method. Problem I am having is that the code in the run part of my task gets executed thousands of times if I only include a Time that I want the task to be executed. You can have a look at the code below.
Any tips will be appreciated.
Cheers,
--Stavris.
The code below sits in my main by the way
Code:
Timer myTimer;// = new Timer();
myTimer = new Timer();
int dailyInterval = 60 * 60 * 24 * 1000;
//same time every day
DateFormat df = new SimpleDateFormat("HH.mm.ss");
Date timeOfEvent = df.parse("10.52.00");
myTimer.scheduleAtFixedRate(new TimerTask() {
public void run(){
try{
System.out.println("Hello");
}
catch(Exception ex){
ex.printStackTrace();
}
}
},timeOfEvent ,dailyInterval);