简体   繁体   English

如何安排任务以很长的周期性间隔运行

[英]How do I schedule a task to run at very long periodic intervals

I am using void java.util.Timer.scheduleAtFixedRate(TimerTask task, long delay, long period) to execute a task at specified "period".我正在使用 void java.util.Timer.scheduleAtFixedRate(TimerTask task, long delay, long period) 在指定的“周期”执行任务。 I want to specify a period which is quite large - the period which is larger then max long value.我想指定一个非常大的周期 -大于最大长值的周期。 i want to use double value to specify the period.我想使用双精度值来指定期间。 Can anyone help me to do is?任何人都可以帮我做吗? Is there any other possible way to execute the task at interval which is very long period.是否有任何其他可能的方法以很长的时间间隔执行任务。 Thanks谢谢

Your not providing enough information on your intent - what lengths of periods are we talking about?您没有提供足够的信息来说明您的意图——我们在谈论多长时间? Days, months, years?几天,几个月,几年?

I suspect your using the wrong tool here.我怀疑你在这里使用了错误的工具。 For job scheduling I'd look at something like Quartz as it support cron-like scheduling where you can specify a schedule in seconds/minutes/hours/days/years.对于作业调度,我会看像Quartz之类的东西,因为它支持类似 cron 的调度,您可以在其中以秒/分钟/小时/天/年为单位指定时间表。

yes its my mistake.是的,这是我的错误。 I was calculating repeat period in wrong way.我以错误的方式计算重复周期。 (7 * 24 * 60 * 60 * 1000) * 5 results in negative value. (7 * 24 * 60 * 60 * 1000) * 5 结果为负值。 After typecasting the answer to long it works fine.在将答案类型化为 long 之后,它工作正常。 (long)5 * 7 * 24 * 60 * 60 * 1000 gives correct value. (long)5 * 7 * 24 * 60 * 60 * 1000 给出了正确的值。 Thanks.谢谢。

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

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