33 |
|
* that sets newly created threads to a known state. |
34 |
|
* <li> Methods that create and return a {@link Callable} |
35 |
|
* out of other closure-like forms, so they can be used |
36 |
< |
* in execution methods requiring <tt>Callable</tt>. |
36 |
> |
* in execution methods requiring {@code Callable}. |
37 |
|
* </ul> |
38 |
|
* |
39 |
|
* @since 1.5 |
44 |
|
/** |
45 |
|
* Creates a thread pool that reuses a fixed number of threads |
46 |
|
* operating off a shared unbounded queue. At any point, at most |
47 |
< |
* <tt>nThreads</tt> threads will be active processing tasks. |
47 |
> |
* {@code nThreads} threads will be active processing tasks. |
48 |
|
* If additional tasks are submitted when all threads are active, |
49 |
|
* they will wait in the queue until a thread is available. |
50 |
|
* If any thread terminates due to a failure during execution |
102 |
|
* Creates a thread pool that reuses a fixed number of threads |
103 |
|
* operating off a shared unbounded queue, using the provided |
104 |
|
* ThreadFactory to create new threads when needed. At any point, |
105 |
< |
* at most <tt>nThreads</tt> threads will be active processing |
105 |
> |
* at most {@code nThreads} threads will be active processing |
106 |
|
* tasks. If additional tasks are submitted when all threads are |
107 |
|
* active, they will wait in the queue until a thread is |
108 |
|
* available. If any thread terminates due to a failure during |
132 |
|
* subsequent tasks.) Tasks are guaranteed to execute |
133 |
|
* sequentially, and no more than one task will be active at any |
134 |
|
* given time. Unlike the otherwise equivalent |
135 |
< |
* <tt>newFixedThreadPool(1)</tt> the returned executor is |
135 |
> |
* {@code newFixedThreadPool(1)} the returned executor is |
136 |
|
* guaranteed not to be reconfigurable to use additional threads. |
137 |
|
* |
138 |
|
* @return the newly created single-threaded Executor |
148 |
|
* Creates an Executor that uses a single worker thread operating |
149 |
|
* off an unbounded queue, and uses the provided ThreadFactory to |
150 |
|
* create a new thread when needed. Unlike the otherwise |
151 |
< |
* equivalent <tt>newFixedThreadPool(1, threadFactory)</tt> the |
151 |
> |
* equivalent {@code newFixedThreadPool(1, threadFactory)} the |
152 |
|
* returned executor is guaranteed not to be reconfigurable to use |
153 |
|
* additional threads. |
154 |
|
* |
171 |
|
* will reuse previously constructed threads when they are |
172 |
|
* available. These pools will typically improve the performance |
173 |
|
* of programs that execute many short-lived asynchronous tasks. |
174 |
< |
* Calls to <tt>execute</tt> will reuse previously constructed |
174 |
> |
* Calls to {@code execute} will reuse previously constructed |
175 |
|
* threads if available. If no existing thread is available, a new |
176 |
|
* thread will be created and added to the pool. Threads that have |
177 |
|
* not been used for sixty seconds are terminated and removed from |
213 |
|
* subsequent tasks.) Tasks are guaranteed to execute |
214 |
|
* sequentially, and no more than one task will be active at any |
215 |
|
* given time. Unlike the otherwise equivalent |
216 |
< |
* <tt>newScheduledThreadPool(1)</tt> the returned executor is |
216 |
> |
* {@code newScheduledThreadPool(1)} the returned executor is |
217 |
|
* guaranteed not to be reconfigurable to use additional threads. |
218 |
|
* @return the newly created scheduled executor |
219 |
|
*/ |
230 |
|
* place if needed to execute subsequent tasks.) Tasks are |
231 |
|
* guaranteed to execute sequentially, and no more than one task |
232 |
|
* will be active at any given time. Unlike the otherwise |
233 |
< |
* equivalent <tt>newScheduledThreadPool(1, threadFactory)</tt> |
233 |
> |
* equivalent {@code newScheduledThreadPool(1, threadFactory)} |
234 |
|
* the returned executor is guaranteed not to be reconfigurable to |
235 |
|
* use additional threads. |
236 |
|
* @param threadFactory the factory to use when creating new |
278 |
|
* casts. This provides a way to safely "freeze" configuration and |
279 |
|
* disallow tuning of a given concrete implementation. |
280 |
|
* @param executor the underlying implementation |
281 |
< |
* @return an <tt>ExecutorService</tt> instance |
281 |
> |
* @return an {@code ExecutorService} instance |
282 |
|
* @throws NullPointerException if executor null |
283 |
|
*/ |
284 |
|
public static ExecutorService unconfigurableExecutorService(ExecutorService executor) { |
294 |
|
* casts. This provides a way to safely "freeze" configuration and |
295 |
|
* disallow tuning of a given concrete implementation. |
296 |
|
* @param executor the underlying implementation |
297 |
< |
* @return a <tt>ScheduledExecutorService</tt> instance |
297 |
> |
* @return a {@code ScheduledExecutorService} instance |
298 |
|
* @throws NullPointerException if executor null |
299 |
|
*/ |
300 |
|
public static ScheduledExecutorService unconfigurableScheduledExecutorService(ScheduledExecutorService executor) { |
309 |
|
* same {@link ThreadGroup}. If there is a {@link |
310 |
|
* java.lang.SecurityManager}, it uses the group of {@link |
311 |
|
* System#getSecurityManager}, else the group of the thread |
312 |
< |
* invoking this <tt>defaultThreadFactory</tt> method. Each new |
312 |
> |
* invoking this {@code defaultThreadFactory} method. Each new |
313 |
|
* thread is created as a non-daemon thread with priority set to |
314 |
< |
* the smaller of <tt>Thread.NORM_PRIORITY</tt> and the maximum |
314 |
> |
* the smaller of {@code Thread.NORM_PRIORITY} and the maximum |
315 |
|
* priority permitted in the thread group. New threads have names |
316 |
|
* accessible via {@link Thread#getName} of |
317 |
|
* <em>pool-N-thread-M</em>, where <em>N</em> is the sequence |
330 |
|
* Executors#defaultThreadFactory}, additionally setting the |
331 |
|
* AccessControlContext and contextClassLoader of new threads to |
332 |
|
* be the same as the thread invoking this |
333 |
< |
* <tt>privilegedThreadFactory</tt> method. A new |
334 |
< |
* <tt>privilegedThreadFactory</tt> can be created within an |
333 |
> |
* {@code privilegedThreadFactory} method. A new |
334 |
> |
* {@code privilegedThreadFactory} can be created within an |
335 |
|
* {@link AccessController#doPrivileged} action setting the |
336 |
|
* current thread's access control context to create threads with |
337 |
|
* the selected permission settings holding within that action. |
363 |
|
* Returns a {@link Callable} object that, when |
364 |
|
* called, runs the given task and returns the given result. This |
365 |
|
* can be useful when applying methods requiring a |
366 |
< |
* <tt>Callable</tt> to an otherwise resultless action. |
366 |
> |
* {@code Callable} to an otherwise resultless action. |
367 |
|
* @param task the task to run |
368 |
|
* @param result the result to return |
369 |
|
* @return a callable object |
377 |
|
|
378 |
|
/** |
379 |
|
* Returns a {@link Callable} object that, when |
380 |
< |
* called, runs the given task and returns <tt>null</tt>. |
380 |
> |
* called, runs the given task and returns {@code null}. |
381 |
|
* @param task the task to run |
382 |
|
* @return a callable object |
383 |
|
* @throws NullPointerException if task null |
419 |
|
|
420 |
|
/** |
421 |
|
* Returns a {@link Callable} object that will, when |
422 |
< |
* called, execute the given <tt>callable</tt> under the current |
422 |
> |
* called, execute the given {@code callable} under the current |
423 |
|
* access control context. This method should normally be |
424 |
|
* invoked within an {@link AccessController#doPrivileged} action |
425 |
|
* to create callables that will, if possible, execute under the |
438 |
|
|
439 |
|
/** |
440 |
|
* Returns a {@link Callable} object that will, when |
441 |
< |
* called, execute the given <tt>callable</tt> under the current |
441 |
> |
* called, execute the given {@code callable} under the current |
442 |
|
* access control context, with the current context class loader |
443 |
|
* as the context class loader. This method should normally be |
444 |
|
* invoked within an {@link AccessController#doPrivileged} action |