ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/ScheduledExecutor.java
Revision: 1.38
Committed: Wed Dec 10 01:51:11 2003 UTC (20 years, 5 months ago) by tim
Branch: MAIN
CVS Tags: HEAD
Changes since 1.37: +0 -0 lines
State: FILE REMOVED
Log Message:
Move and rename static Executors.execute/invoke to ExecutorService.submit/invoke,
providing implementations in AbstractExecutorService (which TPE extends).

File Contents

# User Rev Content
1 tim 1.1 /*
2 dl 1.4 * 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 tim 1.1 */
6    
7     package java.util.concurrent;
8 dl 1.4 import java.util.concurrent.atomic.*;
9 dl 1.2 import java.util.*;
10 tim 1.1
11     /**
12 dl 1.25 * An {@link Executor} that can schedule commands to run after a given
13 dl 1.36 * delay, or to execute periodically.
14 dl 1.7 *
15     * <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 dl 1.22 * <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 dl 1.32 * matter to transform an absolute time represented as a {@link
26 dl 1.33 * java.util.Date} to the required form. For example, to schedule at
27 dl 1.32 * a certain future <tt>date</tt>, you can use: <tt>schedule(task,
28     * date.getTime() - System.currentTimeMillis(),
29 dl 1.22 * 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 dl 1.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 dl 1.9 * @author Doug Lea
38 tim 1.1 */
39 dl 1.36 public interface ScheduledExecutor extends Executor {
40 dl 1.2
41 tim 1.1 /**
42 dl 1.36 * Creates and executes a one-shot action that becomes enabled
43     * after the given delay.
44 dl 1.6 * @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 dl 1.36 * @return a Future representing pending completion of the task,
48 tim 1.37 * and whose <tt>get()</tt> method will return an arbitrary value
49 dl 1.36 * upon completion.
50 dl 1.17 * @throws RejectedExecutionException if task cannot be scheduled
51     * for execution because the executor has been shut down.
52 dl 1.30 * @throws NullPointerException if command is null
53 dl 1.4 */
54    
55 tim 1.37 public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit);
56 dl 1.4
57     /**
58 dl 1.29 * Creates and executes a ScheduledFuture that becomes enabled after the
59     * given delay.
60     * @param callable the function to execute.
61     * @param delay the time from now to delay execution.
62     * @param unit the time unit of the delay parameter.
63     * @return a ScheduledFuture that can be used to extract result or cancel.
64     * @throws RejectedExecutionException if task cannot be scheduled
65     * for execution because the executor has been shut down.
66 dl 1.30 * @throws NullPointerException if callable is null
67 dl 1.29 */
68 dl 1.36 public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit);
69 dl 1.29
70     /**
71 dl 1.7 * Creates and executes a periodic action that becomes enabled first
72 dl 1.4 * after the given initial delay, and subsequently with the given
73 dl 1.7 * period; that is executions will commence after
74     * <tt>initialDelay</tt> then <tt>initialDelay+period</tt>, then
75 dl 1.28 * <tt>initialDelay + 2 * period</tt>, and so on. The
76     * task will only terminate via cancellation.
77 dl 1.6 * @param command the task to execute.
78     * @param initialDelay the time to delay first execution.
79     * @param period the period between successive executions.
80     * @param unit the time unit of the delay and period parameters
81 dl 1.36 * @return a Future representing pending completion of the task,
82     * and whose <tt>get()</tt> method will throw an exception upon
83     * cancellation.
84 dl 1.6 * @throws RejectedExecutionException if task cannot be scheduled
85     * for execution because the executor has been shut down.
86 dl 1.30 * @throws NullPointerException if command is null
87 dl 1.32 * @throws IllegalArgumentException if period less than or equal to zero.
88 dl 1.4 */
89 tim 1.37 public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit);
90 dl 1.7 /**
91     * Creates and executes a periodic action that becomes enabled first
92 dl 1.34 * after the given initial delay, and subsequently with the
93 dl 1.7 * given delay between the termination of one execution and the
94 dl 1.28 * commencement of the next.
95     * The task will only terminate via cancellation.
96 dl 1.7 * @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 dl 1.36 * @return a Future representing pending completion of the task,
102     * and whose <tt>get()</tt> method will throw an exception upon
103     * cancellation.
104 dl 1.7 * @throws RejectedExecutionException if task cannot be scheduled
105     * for execution because the executor has been shut down.
106 dl 1.30 * @throws NullPointerException if command is null
107 dl 1.32 * @throws IllegalArgumentException if delay less than or equal to zero.
108 dl 1.7 */
109 tim 1.37 public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit);
110 dl 1.4
111     /**
112 dl 1.16 * Execute command with zero required delay. This has effect
113 dl 1.36 * equivalent to <tt>schedule(command, 0, anyUnit)</tt>.
114 dl 1.6 * @param command the task to execute
115 dl 1.36 * @throws RejectedExecutionException if this task cannot be
116     * accepted for execution.
117 dl 1.30 * @throws NullPointerException if command is null
118 dl 1.4 */
119 dl 1.36 public void execute(Runnable command);
120 tim 1.1 }