zoukankan      html  css  js  c++  java
  • 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时间执行下一个线程.

  • 相关阅读:
    3.31上午英语视频
    3.30上午
    leetcode 38
    leetcode 36
    leetcode 28
    leetcode 27
    leetcode 26
    leetcode 24
    leetcode 21
    leetcode 20
  • 原文地址:https://www.cnblogs.com/davidwang/p/3499738.html
Copyright © 2011-2022 走看看