扫码关注官方订阅号
ScheduledExecutorService类 scheduleWithFixedDelay() 和 scheduleFixedRate() 区别
业精于勤,荒于嬉;行成于思,毁于随。
我猜你想说的是 scheduleAtFixedRate方法吧
scheduleAtFixedRate(Runnable command,long initialDelay,long period,TimeUnit unit)我们可以使用该方法延迟执行任务,设置任务的执行周期。时间周期从线程池中首先开始执行的线程算起,所以假设period为1s,线程执行了5s,那么下一个线程在第一个线程运行完后会很快被执行。
scheduleWithFixedDelay(Runnable command,long initialDelay,long delay,TimeUnit unit)该方法可被用于延迟周期性执行任务,delaytime是线程停止执行到下一次开始执行之间的延迟时间,假设有下面的代码
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
我猜你想说的是 scheduleAtFixedRate方法吧
scheduleAtFixedRate(Runnable command,long initialDelay,long period,TimeUnit unit)
我们可以使用该方法延迟执行任务,设置任务的执行周期。时间周期从线程池中首先开始执行的线程算起,所以假设period为1s,线程执行了5s,那么下一个线程在第一个线程运行完后会很快被执行。
scheduleWithFixedDelay(Runnable command,long initialDelay,long delay,TimeUnit unit)
该方法可被用于延迟周期性执行任务,delaytime是线程停止执行到下一次开始执行之间的延迟时间,假设有下面的代码