开发者

Java TimerTask Execution Period

开发者 https://www.devze.com 2022-12-14 17:26 出处:网络
Can I overload the 开发者_JS百科Java Timer Task to have it execute every one day? Timer timer = new Timer(true);

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号