ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/ScheduledExecutorService.java
Revision: 1.3
Committed: Fri Dec 19 14:42:25 2003 UTC (20 years, 5 months ago) by dl
Branch: MAIN
Changes since 1.2: +1 -1 lines
Log Message:
Documentation improvements

File Contents

# User Rev Content
1 tim 1.1 /*
2     * Written by Doug Lea with assistance from members of JCP JSR-166
3     * Expert Group and released to the public domain. Use, modify, and
4     * redistribute this code in any way without acknowledgement.
5     */
6    
7     package java.util.concurrent;
8 tim 1.2 import java.util.concurrent.atomic.*;
9     import java.util.*;
10 tim 1.1
11     /**
12 tim 1.2 * An {@link ExecutorService} that can schedule commands to run after a given
13     * delay, or to execute periodically.
14 tim 1.1 *
15 tim 1.2 * <p> The <tt>schedule</tt> methods create tasks with various delays
16     * and return a task object that can be used to cancel or check
17     * execution. The <tt>scheduleAtFixedRate</tt> and
18     * <tt>scheduleWithFixedDelay</tt> methods create and execute tasks
19     * that run periodically until cancelled. Commands submitted using
20     * the <tt>execute</tt> method are scheduled with a requested delay of
21     * zero.
22     *
23     * <p>All <t>schedule</tt> methods accept <em>relative</em> delays and
24     * periods as arguments, not absolute times or dates. It is a simple
25     * matter to transform an absolute time represented as a {@link
26     * java.util.Date} to the required form. For example, to schedule at
27     * a certain future <tt>date</tt>, you can use: <tt>schedule(task,
28     * date.getTime() - System.currentTimeMillis(),
29     * TimeUnit.MILLISECONDS)</tt>. Beware however that expiration of a
30     * relative delay need not coincide with the current <tt>Date</tt> at
31     * which the task is enabled due to network time synchronization
32     * protocols, clock drift, or other factors. Negative relative delays
33     * (but not periods) are allowed in <tt>schedule</tt> methods, and are
34     * treated as requests for immediate execution.
35 tim 1.1 *
36     * @since 1.5
37     * @author Doug Lea
38     */
39 tim 1.2 public interface ScheduledExecutorService extends ExecutorService {
40    
41     /**
42     * Creates and executes a one-shot action that becomes enabled
43     * after the given delay.
44     * @param command the task to execute.
45     * @param delay the time from now to delay execution.
46     * @param unit the time unit of the delay parameter.
47     * @return a Future representing pending completion of the task,
48 dl 1.3 * and whose <tt>get()</tt> method will return <tt>null</tt>
49 tim 1.2 * upon completion.
50     * @throws RejectedExecutionException if task cannot be scheduled
51     * for execution because the executor has been shut down.
52     * @throws NullPointerException if command is null
53     */
54     public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit);
55    
56     /**
57     * Creates and executes a ScheduledFuture that becomes enabled after the
58     * given delay.
59     * @param callable the function to execute.
60     * @param delay the time from now to delay execution.
61     * @param unit the time unit of the delay parameter.
62     * @return a ScheduledFuture that can be used to extract result or cancel.
63     * @throws RejectedExecutionException if task cannot be scheduled
64     * for execution because the executor has been shut down.
65     * @throws NullPointerException if callable is null
66     */
67     public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit);
68    
69     /**
70     * Creates and executes a periodic action that becomes enabled first
71     * after the given initial delay, and subsequently with the given
72     * period; that is executions will commence after
73     * <tt>initialDelay</tt> then <tt>initialDelay+period</tt>, then
74     * <tt>initialDelay + 2 * period</tt>, and so on. The
75     * task will only terminate via cancellation.
76     * @param command the task to execute.
77     * @param initialDelay the time to delay first execution.
78     * @param period the period between successive executions.
79     * @param unit the time unit of the delay and period parameters
80     * @return a Future representing pending completion of the task,
81     * and whose <tt>get()</tt> method will throw an exception upon
82     * cancellation.
83     * @throws RejectedExecutionException if task cannot be scheduled
84     * for execution because the executor has been shut down.
85     * @throws NullPointerException if command is null
86     * @throws IllegalArgumentException if period less than or equal to zero.
87     */
88     public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit);
89    
90     /**
91     * Creates and executes a periodic action that becomes enabled first
92     * after the given initial delay, and subsequently with the
93     * given delay between the termination of one execution and the
94     * commencement of the next.
95     * The task will only terminate via cancellation.
96     * @param command the task to execute.
97     * @param initialDelay the time to delay first execution.
98     * @param delay the delay between the termination of one
99     * execution and the commencement of the next.
100     * @param unit the time unit of the delay and delay parameters
101     * @return a Future representing pending completion of the task,
102     * and whose <tt>get()</tt> method will throw an exception upon
103     * cancellation.
104     * @throws RejectedExecutionException if task cannot be scheduled
105     * for execution because the executor has been shut down.
106     * @throws NullPointerException if command is null
107     * @throws IllegalArgumentException if delay less than or equal to zero.
108     */
109     public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit);
110    
111     /**
112     * Execute command with zero required delay. This has effect
113     * equivalent to <tt>schedule(command, 0, anyUnit)</tt>.
114     * @param command the task to execute
115     * @throws RejectedExecutionException if this task cannot be
116     * accepted for execution.
117     * @throws NullPointerException if command is null
118     */
119     public void execute(Runnable command);
120 tim 1.1 }