Questions tagged «scheduledexecutorservice»

7
scheduleAtFixedRate与scheduleWithFixedDelay
ScheduledExecutorServicescheduleAtFixedRate和scheduleWithFixedDelay方法之间的主要区别是什么? scheduler.scheduleAtFixedRate(new Runnable() { @Override public void run() { System.out.println("scheduleAtFixedRate: " + new Date()); } }, 1, 3L , SECONDS); scheduler.scheduleWithFixedDelay(new Runnable() { @Override public void run() { System.out.println("scheduleWithFixedDelay: " + new Date()); } }, 1, 3L , SECONDS); 它们打印的时间完全相同,似乎它们以完全相同的时间间隔执行。


11
如何使用ScheduledExecutorService每天在特定时间运行某些任务?
我想每天早上5点执行某项任务。因此,我决定使用ScheduledExecutorService此功能,但到目前为止,我已经看到了一些示例,这些示例演示了如何每隔几分钟运行一次任务。 而且我找不到任何示例来说明如何每天在特定时间(上午5点)每天运行任务,并且还考虑了夏令时的事实- 以下是我的代码,每15分钟运行一次- public class ScheduledTaskExample { private final ScheduledExecutorService scheduler = Executors .newScheduledThreadPool(1); public void startScheduleTask() { /** * not using the taskHandle returned here, but it can be used to cancel * the task, or check if it's done (for recurring tasks, that's not * going to be …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.