简体   繁体   中英

Java TimerTask Execution Period

Can I overload the 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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