ScheduledExecutorService類 scheduleWithFixedDelay() 和 scheduleFixedRate() 區(qū)別
1 回答

千萬里不及你
TA貢獻1784條經(jīng)驗 獲得超9個贊
我猜你想說的是 scheduleAtFixedRate方法吧
scheduleAtFixedRate(Runnable command,long initialDelay,long period,TimeUnit unit)
我們可以使用該方法延遲執(zhí)行任務(wù),設(shè)置任務(wù)的執(zhí)行周期。時間周期從線程池中首先開始執(zhí)行的線程算起,所以假設(shè)period為1s,線程執(zhí)行了5s,那么下一個線程在第一個線程運行完后會很快被執(zhí)行。scheduleWithFixedDelay(Runnable command,long initialDelay,long delay,TimeUnit unit)
該方法可被用于延遲周期性執(zhí)行任務(wù),delaytime是線程停止執(zhí)行到下一次開始執(zhí)行之間的延遲時間,假設(shè)有下面的代碼
添加回答
舉報
0/150
提交
取消