Hi Everyone,
I have used java.util.Timer to schedule TimerTask to be run every 2 hours .
But how do I schedule a task to run say everynight at 2 am ?
This might be something easy, I am just overlooking something I guess.
Thanks in Advance
Hi Everyone,
I have used java.util.Timer to schedule TimerTask to be run every 2 hours .
But how do I schedule a task to run say everynight at 2 am ?
This might be something easy, I am just overlooking something I guess.
Thanks in Advance
Call
timer.scheduleAtFixedRate(task, twoAmDate, twentyFourHoursInMillis )
on java.util.Timer
You can make your own Thread to do this.
Use something like:
boolean todayExecuted = false;
while (true)
{
Date now = new Date();
if (now.getHours() == 2)
{
if (!todayExecuted)
{
todayExecuted = true;
doTask(); // The call to the method you want to execute at 2 am
}
}
if (now.getHours() == 0)
{
todayExecuted = false;
}
try { Thread.sleep(216000000L); } catch(Exception e) {} // Wait 1 hour
}