• Concurrent Framework Timer


    在1.5之后的java版本中使用ScheduledExecutorService替代了老旧的Timer.

    ScheduledExecutorService的实现类是ScheduledThreadPoolExecutor, 一个具备Schedule task功能的ThreadPoolExecutor.

    ScheduledExecutorService.submit(..) execute(..) invokeAll(..) 等方法与ExecutorService完全相同.

    ScheduledExecutorService.schedule(Callable<T> callable, long delay, TimeUnit unit), 延迟delay*unit时间执行该线程.

    ScheduledExecutorService.schedule(Runnable command, long delay, TimeUnit unit), 延迟delay*unit时间执行该线程.

    ScheduledExecutorService.scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit), 多次执行该线程, 除非线程抛出Exception或cancelation/termination the executor, 不会并发执行, 延迟(initialDelay + period*(n-1))*unit时间多次执行第n次, 如果一个线程执行时间超过period*unit则在执行完该线程之后立刻开始下一个线程.

    ScheduledExecutorService.scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit)), 多次执行该线程, 除非线程抛出Exception或cancelation/termination the executor, 不会并发执行, 延迟initialDelay*unit时间执行第一个线程, 之后每隔delay*unit时间执行下一个线程.

  • 相关阅读:
    左边菜单导航
    css3实现轮播
    js-统计选项个数
    空间评论。回复。点赞功能
    简单的购物车功能
    字符串常用的几种方法
    React,js实现分页的案列
    python2的cgi程序
    开发环境和工具
    github入门
  • 原文地址:https://www.cnblogs.com/davidwang/p/3499738.html
Copyright © 2020-2023  润新知