如果我想安排与特定日期对齐的定期任务,则使用ScheduledExecutorService是有意义的.但是它没有方法将firstRunDate随后的延迟传递给scheduleAtFixedRate方法.我知道我可以自己取消初始延迟,但是API是否没有提供任何理由?特别是在内部,SES是使用triggerTimes实现的(这是我要传递的内容).
解决方法:
根据文档:
All schedule methods accept relative delays and periods as arguments, not absolute times or dates. It is a simple matter to transform an absolute time represented as a Date to the required form. For example, to schedule at a certain future date, you can use: schedule(task, date.getTime() – System.currentTimeMillis(), TimeUnit.MILLISECONDS). Beware however that expiration of a relative delay need not coincide with the current Date at which the task is enabled due to network time synchronization protocols, clock drift, or other factors.
看来这是一个决定性的决定.众所周知,Date类存在问题.例如,TimeTask的public void scheduleAtFixedRate(TimerTask任务,Date firstTime,长周期)
不考虑夏时制时间.