12 |
|
import java.security.PrivilegedExceptionAction; |
13 |
|
|
14 |
|
/** |
15 |
< |
* An <tt>Executor</tt> that provides methods to manage termination |
16 |
< |
* and methods that can produce a {@link Future} for tracking |
17 |
< |
* progress of one or more asynchronous tasks. |
18 |
< |
* <p> |
15 |
> |
* An {@link Executor} that provides methods to manage termination and |
16 |
> |
* methods that can produce a {@link Future} for tracking progress of |
17 |
> |
* one or more asynchronous tasks. <p> |
18 |
|
* |
19 |
|
* An <tt>ExecutorService</tt> can be shut down, which will cause it |
20 |
|
* to stop accepting new tasks. After being shut down, the executor |
22 |
|
* executing, no tasks are awaiting execution, and no new tasks can be |
23 |
|
* submitted. |
24 |
|
* |
25 |
< |
* <p> Method <tt>submit</tt> extends base method <tt>execute</tt> by |
26 |
< |
* creating and returning a {@link Future} that can be used to cancel |
27 |
< |
* execution and/or wait for completion. Methods <tt>invokeAny</tt> |
28 |
< |
* and <tt>invokeAll</tt> perform the most commonly useful forms of |
29 |
< |
* bulk execution, executing a collection of tasks and then waiting |
30 |
< |
* for at least one, or all to complete. (Class {@link |
31 |
< |
* ExecutorCompletionService} can be used to write customizable |
32 |
< |
* versions of such methods.) |
25 |
> |
* <p> Method <tt>submit</tt> extends base method {@link |
26 |
> |
* Executor#execute} by creating and returning a {@link Future} that |
27 |
> |
* can be used to cancel execution and/or wait for completion. |
28 |
> |
* Methods <tt>invokeAny</tt> and <tt>invokeAll</tt> perform the most |
29 |
> |
* commonly useful forms of bulk execution, executing a collection of |
30 |
> |
* tasks and then waiting for at least one, or all, to |
31 |
> |
* complete. (Class {@link ExecutorCompletionService} can be used to |
32 |
> |
* write customized variants of these methods.) |
33 |
|
* |
34 |
|
* <p>The {@link Executors} class provides factory methods for the |
35 |
|
* executor services provided in this package. |
39 |
|
*/ |
40 |
|
public interface ExecutorService extends Executor { |
41 |
|
|
43 |
– |
|
42 |
|
/** |
43 |
|
* Initiates an orderly shutdown in which previously submitted |
44 |
|
* tasks are executed, but no new tasks will be |
107 |
|
* representing the pending results of the task. |
108 |
|
* |
109 |
|
* <p> |
110 |
< |
* Note that if you would like to immediately block waiting |
110 |
> |
* If you would like to immediately block waiting |
111 |
|
* for a task, you can use constructions of the form |
112 |
|
* <tt>result = exec.submit(aCallable).get();</tt> |
113 |
+ |
* |
114 |
+ |
* <p> Note: The {@link Executors} class includes a set of methods |
115 |
+ |
* that can convert some other common closure-like objects, |
116 |
+ |
* for example, {@link java.security.PrivilegedAction} to |
117 |
+ |
* {@link Callable} form so they can be submitted. |
118 |
+ |
* |
119 |
|
* @param task the task to submit |
120 |
|
* @return a Future representing pending completion of the task |
121 |
|
* @throws RejectedExecutionException if task cannot be scheduled |
122 |
|
* for execution |
123 |
+ |
* @throws NullPointerException if task null |
124 |
|
*/ |
125 |
|
<T> Future<T> submit(Callable<T> task); |
126 |
|
|
127 |
|
/** |
128 |
|
* Submits a Runnable task for execution and returns a Future |
129 |
+ |
* representing that task that will upon completion return |
130 |
+ |
* the given result |
131 |
+ |
* |
132 |
+ |
* @param task the task to submit |
133 |
+ |
* @param result the result to return |
134 |
+ |
* @return a Future representing pending completion of the task, |
135 |
+ |
* and whose <tt>get()</tt> method will return the given result |
136 |
+ |
* upon completion. |
137 |
+ |
* @throws RejectedExecutionException if task cannot be scheduled |
138 |
+ |
* for execution |
139 |
+ |
* @throws NullPointerException if task null |
140 |
+ |
*/ |
141 |
+ |
<T> Future<T> submit(Runnable task, T result); |
142 |
+ |
|
143 |
+ |
/** |
144 |
+ |
* Submits a Runnable task for execution and returns a Future |
145 |
|
* representing that task. |
146 |
|
* |
147 |
|
* @param task the task to submit |
150 |
|
* upon completion. |
151 |
|
* @throws RejectedExecutionException if task cannot be scheduled |
152 |
|
* for execution |
153 |
+ |
* @throws NullPointerException if task null |
154 |
|
*/ |
155 |
|
Future<?> submit(Runnable task); |
156 |
|
|