定时调度线程池scheduleAtFixedRate和schedule方法
来源:互联网 发布:企业淘宝账户怎么注册 编辑:程序博客网 时间:2024/05/29 04:07
【1.scheduleAtFixedRate方法】
定时调度线程池:ScheduledExecutorService executor=Executors.newScheduledThreadPool(2);//提供2个定时调度的线程
定时调度线程池:ScheduledExecutorService executor=Executors.newScheduledThreadPool(2);//提供2个定时调度的线程
executor.scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit)
- Parameters:
- command the task to execute
- initialDelay the time to delay first execution 线程第一次执行的初始时延
- period the period between successive executions 两个连续线程的周期
- unit the time unit of the initialDelay and period parameters
Note:Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period; that is executions will commence after initialDelay
then initialDelay+period
, theninitialDelay + 2 * period
, and so on. If any execution of the task encounters an exception, subsequent executions are suppressed(压制). Otherwise, the task will only terminate via cancellation or termination of the executor.If any execution of this task takes longer than its period, then subsequent executions may start late, but will not concurrently execute.
如果一个线程运行的时间大于周期period,后面的线程可能会晚一点启动,但不会同时执行。
【2.schedule方法】
executor.schedule(Runnable command,long delay, TimeUnit unit)
@param command the task to execute 进行调度的线程
@param delay the time from now to delay execution 延迟时间
@param unit the time unit of the delay parameter 时间单位(毫秒MILLISECONDS、微妙等)
0 0
- 定时调度线程池scheduleAtFixedRate和schedule方法
- schedule方法和scheduleAtFixedRate方法的区别
- TImer定时器的方法schedule和scheduleAtFixedRate区别已经动态修改定时计划的实现
- 定时任务中的 Timer的schedule和scheduleAtFixedRate方法的区别
- Timer的schedule和scheduleAtFixedRate方法辨析
- 方法schedule与scheduleAtFixedRate
- schedule和scheduleAtFixedRate
- schedule和scheduleAtFixedRate
- schedule和scheduleAtFixedRate
- schedule和scheduleAtFixedRate区别
- schedule和scheduleAtFixedRate
- schedule和scheduleAtFixedRate区别
- (转)schedule和scheduleAtFixedRate
- schedule和scheduleAtFixedRate
- schedule和scheduleAtFixedRate
- schedule和scheduleAtFixedRate区别
- schedule和scheduleAtFixedRate区别
- schedule和scheduleAtFixedRate区别
- spark机器学习笔记:(二)用Spark Python进行数据处理和特征提取
- js正则实现前端搜索,匹配字符加红
- LeetCode Largest Divisible Subset(动态规划)
- mongodb的聚合函数的$group方法运用。
- DrawerLayout的简单使用
- 定时调度线程池scheduleAtFixedRate和schedule方法
- 经常用到的Itent完全理解
- jackson 对象转换成json
- rsync+inotify实现服务器之间文件实时同步
- 如何在 Flickr 上找到又酷,又有趣,且版权自由的照片?
- 水仙花数和递归调用举例
- <![CDATA[]]>和转义字符
- 在线将pdf转换成jpg格式的方法
- 如何在 Flickr 上找到又酷,又有趣,且版权自由的照片?