简体   繁体   English

Java TimerTask执行期

[英]Java TimerTask Execution Period

Can I overload the Java Timer Task to have it execute every one day? 我可以重载Java Timer Task使其每天执行吗?

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. 从应用程序开始运行的时间开始,计时器将在延迟6000000毫秒然后每86400000毫秒后执行SendEmailTask()

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. 如果是这样,尝试Timer.scheduleAtFixedRate (该Timer.schedule方法将过期的特定period前面的届满后; scheduleAtFixedRate期满指定period的初始延迟之后。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM