我想先安排一項任務經常發生,然後再減少一次。我寧願不爲這個添加一個依賴到Quartz。優雅的非線性任務調度?
在標準的Java庫,我已經拿出最好的是一系列的一次性任務,其次是頻率較低的線性時間表:
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
myRunnable = new MyRunnable();
executor.schedule(myRunnable, 0, TimeUnit.SECONDS);
executor.schedule(myRunnable, 5, TimeUnit.SECONDS);
executor.schedule(myRunnable, 10, TimeUnit.SECONDS);
executor.schedule(myRunnable, 15, TimeUnit.SECONDS);
executor.schedule(myRunnable, 30, TimeUnit.SECONDS);
executor.schedule(myRunnable, 45, TimeUnit.SECONDS);
executor.scheduleWithFixedDelay(myRunnable, 60, 300, TimeUnit.SECONDS);
有沒有更好的方法?
哦,我以前做過。感謝您的提醒。 –