ScheduledExecutorService 定时任务,scheduleAtFixedRate和scheduleWithFixedDelay区别

来源:互联网 发布:电脑照片打印排版软件 编辑:程序博客网 时间:2024/05/25 18:12

比Timer用着方便,用过很多次,经常被用

scheduleWithFixedDelay,每一次以固定的延迟时间开始调度task

参数1 command the task to execute2 initialDelay the time to delay first execution3 delay the delay between the termination of one execution  and the commencement of the next4 unit the time unit of the initialDelay and delay parameters解释第一次调度开始时间点=当前时间+initialDelay 下一次调度开始时间点=上一次task完成时间点+delay

scheduleAtFixedRate,每一次以固定的频率开始调度task

这是参数1 command the task to execute2 initialDelay the time to delay first execution3 period the period between successive executions4 unit the time unit of the initialDelay and period parameters解释第一次调度开始时间点=当前时间+initialDelay第二次调度开始时间点=initialDelay + perid第n次调度开始时间点=initialDelay + n *perid比如:现在是12:00启动服务 设定initialDelay=1;period=2;unit=小时第一次:12:00 + 1 =13:00第二次:12:00 + 1 +2 =15:00第三次次:12:00 +1 + 2 + 2 =17:00...
阅读全文
0 0
原创粉丝点击