gpt4 book ai didi

java - 为什么 ScheduledExecutorService 不公开在特定时间运行的方法

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:03:16 25 4
gpt4 key购买 nike

如果我想安排与特定日期一致的重复性任务,那么使用 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 task, Date firstTime, long period)
不考虑夏令时。

关于java - 为什么 ScheduledExecutorService 不公开在特定时间运行的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3883320/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com