1 /**
2 * 创建并执行在给定延迟后启用的一次性操作
3 *
4 * @param command 要执行的任务
5 * @param delay 从现在开始延迟执行的时间
6 * @param unit 延时参数的时间单位
7 * @return 表示任务等待完成,并且其的ScheduledFuture get()方法将返回 null完成后
8 * @throws RejectedExecutionException 如果任务无法安排执行
9 * @throws NullPointerException 如果命令为空
10 */
11 public ScheduledFuture<?> schedule(Runnable command,
12 long delay, TimeUnit unit);
13
14 /**
15 * 创建并执行在给定延迟后启用的ScheduledFuture。
16 *
17 * @param callable 执行的功能
18 * @param delay 从现在开始延迟执行的时间
19 * @param unit 延迟参数的时间单位
20 * @param <V> the 可调用结果的类型
21 * @return一个可用于提取结果或取消的ScheduledFuture
22 * @throws RejectedExecutionException 如果该任务无法安排执行
23 * @throws NullPointerException 如果callable为空
24 */
25 public <V> ScheduledFuture<V> schedule(Callable<V> callable,
26 long delay, TimeUnit unit);
27
28 /**
29 * 创建并执行一个在给定初始延迟后首次启用的定期操作,后续操作具有给定的周期;也就是将在initialDelay后开始执行,然后在
30 * initialDelay+period后执行,接着在initialDelay + 2 * period后执行,依此类推。
31 * 如果任务的执行遇到异常,则后续的执行被抑制。 否则,任务将仅通过取消或终止执行人终止。
32 * 如果任务执行时间比其周期长,则后续执行可能会迟到,但不会同时执行。
33 *
34 * @param command 要执行的任务
35 * @param initialDelay 首次执行的延迟时间
36 * @param period 连续执行之间的周期
37 * @param unit initialDelay和period参数的时间单位
38 * @return 一个ScheduledFuture代表待完成的任务,其 get()方法将在取消时抛出异常
39 * @throws RejectedExecutionException 如果任务无法安排执行
40 * @throws NullPointerException 如果命令为空
41 * @throws IllegalArgumentException 如果period小于或等于零
42 */
43 public ScheduledFuture<?> scheduleAtFixedRate(Runnable command,
44 long initialDelay,
45 long period,
46 TimeUnit unit);
47
48 /**
49 * 创建并执行一个在给定初始延迟后首次启用的定期操作,随后,在每一次执行终止和下一次执行开始之间都存在给定的延迟。
50 * 如果任务的执行遇到异常,则后续的执行被抑制。 否则,任务将仅通过取消或终止执行人终止。
51 *
52 * @param command 要执行的任务
53 * @param initialDelay 首次执行的延迟时间
54 * @param delay 一次执行终止和下一次执行开始之间的延迟
55 * @param unit initialDelay和delay参数的时间单位
56 * @return 表示挂起任务完成的ScheduledFuture,并且其get()方法在取消后将抛出异常
57 * @throws RejectedExecutionException 如果任务不能安排执行
58 * @throws NullPointerException 如果command为null
59 * @throws IllegalArgumentException 如果delay小于等于0
60 */
61 public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command,
62 long initialDelay,
63 long delay,
64 TimeUnit unit);