Java TimerTask Execution Period
Can I overload the 开发者_JS百科Java Timer Task to have it execute every one day?
Timer timer = new Timer(true);
timer.schedule(new SendEmailTask(), 6000000, 86400000); //schedule to run one day?
Will there be no problem if I implement below period?
the timer will execute the SendEmailTask()
after a delay of 6000000 ms and then every 86400000 ms, starting from the time your application starts to run.
you are not overloading the timer your are merely using an instance of a timer.
it goes without saying that if your application is not running your timer event wont execute as well.
Are you trying to get the timer to run once every day at exactly the same time of day? If so, try Timer.scheduleAtFixedRate
(the Timer.schedule
method will expire a specified period
after the previous expiry; scheduleAtFixedRate
expires a specified period
after the initial delay.
精彩评论