Need help on Task Scheduling using Timer task
Hi all,
Does any body know how to schedule a task at any given time using Timertask. Say i want to execute a task at 4:00 AM. but the timer task is executing the task at 4:00 AM and as well as at 4:00 PM also. But i don't want to execute the task at 4:00 PM. So how to specify the start time exactly as 4:00 AM only.How to specify the exact start time for timer task . please refer the following code how i have implemented
Looking for any kind of help or hints or suggestions.
Thanks in advance
Date startTime = getExecutionTime(4,0);
timer=new java.util.Timer();
ImportingTask task = new ImportingTask();
timer.scheduleAtFixedRate(task,startTime,interval);
private Date getExecutionTime(int hours,int minutes ){
GregorianCalendar present_Cal = new GregorianCalendar();
GregorianCalendar result = new GregorianCalendar(
present_Cal.get(Calendar.YEAR),
present_Cal.get(Calendar.MONTH),
present_Cal.get(Calendar.DATE),
hours,
minutes );
return result ;
}
class ImportingTask extends TimerTask{
public void run(){
executeScheduledJob();
}
}
Hi
I Need the task to be Started at 4.00 AM and it need to run at an interval of 1 hour , that means the task should need to be execute at 4:00 AM, 5:00 AM and soo on ...... so i gev the the interval as3600000 milli seconds.
timer.scheduleAtFixedRate(task,startTime,interval);
But my problem is the execution starts at 4.00 PM also, But i want the execution should be at 4.00 AM only
Looking for your advice Thanks alot in advance
Hi
I Need the task to be Started at 4.00 AM and it need to run at an interval of 1 hour , that means the task need to be execute at 4:00 AM, 5:00 AM and soo on ...... so i gave the the interval as3600000 milli seconds.
timer.scheduleAtFixedRate(task,startTime,interval);
But the problem is the execution starts at 4.00 PM also, But i want the execution should be at 4.00 AM only
Looking for your advice Thanks alot in advance
Sorry, I really don't understand the schedule of your timer?
You want to start it (first execution) at 4:00 AM, and then at an interval of 1 hour, is that right?
Well, then after 12 hours (its 4:00 PM by now) it will execute again!
Maybe you should post an exact timetable (24 hours) for the exceutions.
I also have a similar problem.
I used timer.scheduledAtFixedRate(MyTimerTask, start date, period). The start date is today 6:00AM and the period is 24 hours. It works fine. My problem is that I would like the user to enter a specific number of minutes or hours before it should start again.
The current program starts initially at 6:00AM then it stops after 24 hours (which is 6:00AM the next day) and runs again.
What I would like is that after 24 hours, the user can input, say, 5 mins......thus, the program should run at 6:05AM. Then it should run again at 6:10AM the next day and so forth.
Can scheduledAtFixedRate handle this? Thanks in advance!