计时器与ScheduledExecutorService调度 [英] Timer vs. ScheduledExecutorService scheduling

查看:99
本文介绍了计时器与ScheduledExecutorService调度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ScheduledExecutorService 可以直接替换Timer 类,已经在众多 StackOverflow 主题中进行了讨论:

One of the recommended uses of the ScheduledExecutorService is as a direct replacement for the Timer class, as discussed in numerous StackOverflow topics already:

但是, ScheduledExecutorService Timer 支持的方法的命名约定不同.例如,尽管它们都具有 scheduleAtFixedRate()方法,但是Timer方法

However, the naming conventions of the methods supported by ScheduledExecutorService and Timer, are not identical. For example, whereas they both have a scheduleAtFixedRate() method, the Timer method

  • 时间表(TimerTask任务,延迟长,时间长)

没有同名对手.

ScheduledExecutorService 方法

  • scheduleWithFixedDelay(可运行命令,长initialDelay,长延迟,TimeUnit单位)

要代替的那个?

推荐答案

创建并执行一个周期性的操作,该操作首先被启用在给定的初始延迟之后,然后在给定的延迟之后在终止执行与开始执行之间接下来.

Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given delay between the termination of one execution and the commencement of the next.

https://docs.oracle.com/javase/7/docs/api/java/util/Timer.html#schedule(java.util.TimerTask,%20long,%20long)

计划指定的任务以重复执行固定延迟,在指定的延迟后开始.随后执行死刑大约每隔固定的时间间隔,即按指定的时间间隔.

Schedules the specified task for repeated fixed-delay execution, beginning after the specified delay. Subsequent executions take place at approximately regular intervals separated by the specified period.

我会说-是;-)

这篇关于计时器与ScheduledExecutorService调度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆