1 *java.util.concurrent.ThreadPoolExecutor* *ThreadPoolExecutor* AnExecutorService
3 public class ThreadPoolExecutor
4 extends |java.util.concurrent.AbstractExecutorService|
6 |java.util.concurrent.ThreadPoolExecutor_Description|
7 |java.util.concurrent.ThreadPoolExecutor_Fields|
8 |java.util.concurrent.ThreadPoolExecutor_Constructors|
9 |java.util.concurrent.ThreadPoolExecutor_Methods|
11 ================================================================================
13 *java.util.concurrent.ThreadPoolExecutor_Constructors*
14 |java.util.concurrent.ThreadPoolExecutor(int,int,long,TimeUnit,BlockingQueue)|C
15 |java.util.concurrent.ThreadPoolExecutor(int,int,long,TimeUnit,BlockingQueue,RejectedExecutionHandler)|
16 |java.util.concurrent.ThreadPoolExecutor(int,int,long,TimeUnit,BlockingQueue,ThreadFactory)|
17 |java.util.concurrent.ThreadPoolExecutor(int,int,long,TimeUnit,BlockingQueue,ThreadFactory,RejectedExecutionHandler)|
19 *java.util.concurrent.ThreadPoolExecutor_Methods*
20 |java.util.concurrent.ThreadPoolExecutor.afterExecute(Runnable,Throwable)|Metho
21 |java.util.concurrent.ThreadPoolExecutor.awaitTermination(long,TimeUnit)|
22 |java.util.concurrent.ThreadPoolExecutor.beforeExecute(Thread,Runnable)|Method
23 |java.util.concurrent.ThreadPoolExecutor.execute(Runnable)|Executes the given t
24 |java.util.concurrent.ThreadPoolExecutor.finalize()|Invokes shutdown when this
25 |java.util.concurrent.ThreadPoolExecutor.getActiveCount()|Returns the approxima
26 |java.util.concurrent.ThreadPoolExecutor.getCompletedTaskCount()|Returns the ap
27 |java.util.concurrent.ThreadPoolExecutor.getCorePoolSize()|Returns the core num
28 |java.util.concurrent.ThreadPoolExecutor.getKeepAliveTime(TimeUnit)|Returns the
29 |java.util.concurrent.ThreadPoolExecutor.getLargestPoolSize()|Returns the large
30 |java.util.concurrent.ThreadPoolExecutor.getMaximumPoolSize()|Returns the maxim
31 |java.util.concurrent.ThreadPoolExecutor.getPoolSize()|Returns the current numb
32 |java.util.concurrent.ThreadPoolExecutor.getQueue()|Returns the task queue used
33 |java.util.concurrent.ThreadPoolExecutor.getRejectedExecutionHandler()|Returns
34 |java.util.concurrent.ThreadPoolExecutor.getTaskCount()|Returns the approximate
35 |java.util.concurrent.ThreadPoolExecutor.getThreadFactory()|Returns the thread
36 |java.util.concurrent.ThreadPoolExecutor.isShutdown()|
37 |java.util.concurrent.ThreadPoolExecutor.isTerminated()|
38 |java.util.concurrent.ThreadPoolExecutor.isTerminating()|Returns true if this e
39 |java.util.concurrent.ThreadPoolExecutor.prestartAllCoreThreads()|Starts all co
40 |java.util.concurrent.ThreadPoolExecutor.prestartCoreThread()|Starts a core thr
41 |java.util.concurrent.ThreadPoolExecutor.purge()|Tries to remove from the work
42 |java.util.concurrent.ThreadPoolExecutor.remove(Runnable)|Removes this task fro
43 |java.util.concurrent.ThreadPoolExecutor.setCorePoolSize(int)|Sets the core num
44 |java.util.concurrent.ThreadPoolExecutor.setKeepAliveTime(long,TimeUnit)|Sets t
45 |java.util.concurrent.ThreadPoolExecutor.setMaximumPoolSize(int)|Sets the maxim
46 |java.util.concurrent.ThreadPoolExecutor.setRejectedExecutionHandler(RejectedExecutionHandler)|
47 |java.util.concurrent.ThreadPoolExecutor.setThreadFactory(ThreadFactory)|Sets t
48 |java.util.concurrent.ThreadPoolExecutor.shutdown()|Initiates an orderly shutdo
49 |java.util.concurrent.ThreadPoolExecutor.shutdownNow()|Attempts to stop all act
50 |java.util.concurrent.ThreadPoolExecutor.terminated()|Method invoked when the E
52 *java.util.concurrent.ThreadPoolExecutor_Description*
54 An (|java.util.concurrent.ExecutorService|) that executes each submitted task
55 using one of possibly several pooled threads, normally configured using
56 (|java.util.concurrent.Executors|) factory methods.
58 Thread pools address two different problems: they usually provide improved
59 performance when executing large numbers of asynchronous tasks, due to reduced
60 per-task invocation overhead, and they provide a means of bounding and managing
61 the resources, including threads, consumed when executing a collection of
62 tasks. Each ThreadPoolExecutor also maintains some basic statistics, such as
63 the number of completed tasks.
65 To be useful across a wide range of contexts, this class provides many
66 adjustable parameters and extensibility hooks. However, programmers are urged
67 to use the more convenient (|java.util.concurrent.Executors|) factory methods
68 (|java.util.concurrent.Executors|) (unbounded thread pool, with automatic
69 thread reclamation), (|java.util.concurrent.Executors|) (fixed size thread
70 pool) and (|java.util.concurrent.Executors|) (single background thread), that
71 preconfigure settings for the most common usage scenarios. Otherwise, use the
72 following guide when manually configuring and tuning this class:
76 Core and maximum pool sizes
78 A ThreadPoolExecutor will automatically adjust the pool size (see
79 (|java.util.concurrent.ThreadPoolExecutor|) ) according to the bounds set by
80 corePoolSize (see (|java.util.concurrent.ThreadPoolExecutor|) ) and
81 maximumPoolSize (see (|java.util.concurrent.ThreadPoolExecutor|) ). When a new
82 task is submitted in method (|java.util.concurrent.ThreadPoolExecutor|) , and
83 fewer than corePoolSize threads are running, a new thread is created to handle
84 the request, even if other worker threads are idle. If there are more than
85 corePoolSize but less than maximumPoolSize threads running, a new thread will
86 be created only if the queue is full. By setting corePoolSize and
87 maximumPoolSize the same, you create a fixed-size thread pool. By setting
88 maximumPoolSize to an essentially unbounded value such as Integer.MAX_VALUE,
89 you allow the pool to accommodate an arbitrary number of concurrent tasks. Most
90 typically, core and maximum pool sizes are set only upon construction, but they
91 may also be changed dynamically using
92 (|java.util.concurrent.ThreadPoolExecutor|) and
93 (|java.util.concurrent.ThreadPoolExecutor|) .
95 On-demand construction
97 By default, even core threads are initially created and started only when
98 needed by new tasks, but this can be overridden dynamically using method
99 (|java.util.concurrent.ThreadPoolExecutor|) or
100 (|java.util.concurrent.ThreadPoolExecutor|) .
104 New threads are created using a (|java.util.concurrent.ThreadFactory|) . If not
105 otherwise specified, a (|java.util.concurrent.Executors|) is used, that creates
106 threads to all be in the same (|java.lang.ThreadGroup|) and with the same
107 NORM_PRIORITY priority and non-daemon status. By supplying a different
108 ThreadFactory, you can alter the thread's name, thread group, priority, daemon
109 status, etc. If a ThreadFactory fails to create a thread when asked by
110 returning null from newThread, the executor will continue, but might not be
111 able to execute any tasks.
115 If the pool currently has more than corePoolSize threads, excess threads will
116 be terminated if they have been idle for more than the keepAliveTime (see
117 (|java.util.concurrent.ThreadPoolExecutor|) ). This provides a means of
118 reducing resource consumption when the pool is not being actively used. If the
119 pool becomes more active later, new threads will be constructed. This parameter
120 can also be changed dynamically using method
121 (|java.util.concurrent.ThreadPoolExecutor|) . Using a value of Long.MAX_VALUE
122 (|java.util.concurrent.TimeUnit|) effectively disables idle threads from ever
123 terminating prior to shut down.
127 Any (|java.util.concurrent.BlockingQueue|) may be used to transfer and hold
128 submitted tasks. The use of this queue interacts with pool sizing:
132 If fewer than corePoolSize threads are running, the Executor always prefers
133 adding a new thread rather than queuing.
135 If corePoolSize or more threads are running, the Executor always prefers
136 queuing a request rather than adding a new thread.
138 If a request cannot be queued, a new thread is created unless this would exceed
139 maximumPoolSize, in which case, the task will be rejected.
143 There are three general strategies for queuing:
145 Direct handoffs. A good default choice for a work queue is a
146 (|java.util.concurrent.SynchronousQueue|) that hands off tasks to threads
147 without otherwise holding them. Here, an attempt to queue a task will fail if
148 no threads are immediately available to run it, so a new thread will be
149 constructed. This policy avoids lockups when handling sets of requests that
150 might have internal dependencies. Direct handoffs generally require unbounded
151 maximumPoolSizes to avoid rejection of new submitted tasks. This in turn admits
152 the possibility of unbounded thread growth when commands continue to arrive on
153 average faster than they can be processed.
155 Unbounded queues. Using an unbounded queue (for example a
156 (|java.util.concurrent.LinkedBlockingQueue|) without a predefined capacity)
157 will cause new tasks to be queued in cases where all corePoolSize threads are
158 busy. Thus, no more than corePoolSize threads will ever be created. (And the
159 value of the maximumPoolSize therefore doesn't have any effect.) This may be
160 appropriate when each task is completely independent of others, so tasks cannot
161 affect each others execution; for example, in a web page server. While this
162 style of queuing can be useful in smoothing out transient bursts of requests,
163 it admits the possibility of unbounded work queue growth when commands continue
164 to arrive on average faster than they can be processed.
166 Bounded queues. A bounded queue (for example, an
167 (|java.util.concurrent.ArrayBlockingQueue|) ) helps prevent resource exhaustion
168 when used with finite maximumPoolSizes, but can be more difficult to tune and
169 control. Queue sizes and maximum pool sizes may be traded off for each other:
170 Using large queues and small pools minimizes CPU usage, OS resources, and
171 context-switching overhead, but can lead to artificially low throughput. If
172 tasks frequently block (for example if they are I/O bound), a system may be
173 able to schedule time for more threads than you otherwise allow. Use of small
174 queues generally requires larger pool sizes, which keeps CPUs busier but may
175 encounter unacceptable scheduling overhead, which also decreases throughput.
183 New tasks submitted in method (|java.util.concurrent.ThreadPoolExecutor|) will
184 be rejected when the Executor has been shut down, and also when the Executor
185 uses finite bounds for both maximum threads and work queue capacity, and is
186 saturated. In either case, the execute method invokes the
187 (|java.util.concurrent.RejectedExecutionHandler|) method of its
188 (|java.util.concurrent.RejectedExecutionHandler|) . Four predefined handler
189 policies are provided:
193 In the default (|java.util.concurrent.ThreadPoolExecutor.AbortPolicy|) , the
194 handler throws a runtime (|java.util.concurrent.RejectedExecutionException|)
197 In (|java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy|) , the thread
198 that invokes execute itself runs the task. This provides a simple feedback
199 control mechanism that will slow down the rate that new tasks are submitted.
201 In (|java.util.concurrent.ThreadPoolExecutor.DiscardPolicy|) , a task that
202 cannot be executed is simply dropped.
204 In (|java.util.concurrent.ThreadPoolExecutor.DiscardOldestPolicy|) , if the
205 executor is not shut down, the task at the head of the work queue is dropped,
206 and then execution is retried (which can fail again, causing this to be
211 It is possible to define and use other kinds of
212 (|java.util.concurrent.RejectedExecutionHandler|) classes. Doing so requires
213 some care especially when policies are designed to work only under particular
214 capacity or queuing policies.
218 This class provides protected overridable
219 (|java.util.concurrent.ThreadPoolExecutor|) and
220 (|java.util.concurrent.ThreadPoolExecutor|) methods that are called before and
221 after execution of each task. These can be used to manipulate the execution
222 environment; for example, reinitializing ThreadLocals, gathering statistics, or
223 adding log entries. Additionally, method
224 (|java.util.concurrent.ThreadPoolExecutor|) can be overridden to perform any
225 special processing that needs to be done once the Executor has fully
228 If hook or callback methods throw exceptions, internal worker threads may in
229 turn fail and abruptly terminate.
233 Method (|java.util.concurrent.ThreadPoolExecutor|) allows access to the work
234 queue for purposes of monitoring and debugging. Use of this method for any
235 other purpose is strongly discouraged. Two supplied methods,
236 (|java.util.concurrent.ThreadPoolExecutor|) and
237 (|java.util.concurrent.ThreadPoolExecutor|) are available to assist in storage
238 reclamation when large numbers of queued tasks become cancelled.
240 Extension example. Most extensions of this class override one or more of the
241 protected hook methods. For example, here is a subclass that adds a simple
242 pause/resume feature:
246 class PausableThreadPoolExecutor extends ThreadPoolExecutor { private boolean
247 isPaused; private ReentrantLock pauseLock = new ReentrantLock(); private
248 Condition unpaused = pauseLock.newCondition();
250 public PausableThreadPoolExecutor(...) { super(...); }
252 protected void beforeExecute(Thread t, Runnable r) { super.beforeExecute(t, r);
253 pauseLock.lock(); try { while (isPaused) unpaused.await(); }
254 catch(InterruptedException ie) { t.interrupt(); } finally { pauseLock.unlock();
257 public void pause() { pauseLock.lock(); try { isPaused = true; } finally {
258 pauseLock.unlock(); } }
260 public void resume() { pauseLock.lock(); try { isPaused = false;
261 unpaused.signalAll(); } finally { pauseLock.unlock(); } } }
264 *java.util.concurrent.ThreadPoolExecutor(int,int,long,TimeUnit,BlockingQueue)*
266 public ThreadPoolExecutor(
270 java.util.concurrent.TimeUnit unit,
271 java.util.concurrent.BlockingQueue workQueue)
273 Creates a new ThreadPoolExecutor with the given initial parameters and default
274 thread factory and handler. It may be more convenient to use one of the
275 (|java.util.concurrent.Executors|) factory methods instead of this general
278 corePoolSize - the number of threads to keep in the pool, even if they are idle.
279 maximumPoolSize - the maximum number of threads to allow in the pool.
280 keepAliveTime - when the number of threads is greater than the core, this is the maximum time
281 that excess idle threads will wait for new tasks before terminating.
282 unit - the time unit for the keepAliveTime argument.
283 workQueue - the queue to use for holding tasks before they are executed. This queue will
284 hold only the Runnable tasks submitted by the execute method.
286 *java.util.concurrent.ThreadPoolExecutor(int,int,long,TimeUnit,BlockingQueue,RejectedExecutionHandler)*
288 public ThreadPoolExecutor(
292 java.util.concurrent.TimeUnit unit,
293 java.util.concurrent.BlockingQueue workQueue,
294 java.util.concurrent.RejectedExecutionHandler handler)
296 Creates a new ThreadPoolExecutor with the given initial parameters.
298 corePoolSize - the number of threads to keep in the pool, even if they are idle.
299 maximumPoolSize - the maximum number of threads to allow in the pool.
300 keepAliveTime - when the number of threads is greater than the core, this is the maximum time
301 that excess idle threads will wait for new tasks before terminating.
302 unit - the time unit for the keepAliveTime argument.
303 workQueue - the queue to use for holding tasks before they are executed. This queue will
304 hold only the Runnable tasks submitted by the execute method.
305 handler - the handler to use when execution is blocked because the thread bounds and
306 queue capacities are reached.
308 *java.util.concurrent.ThreadPoolExecutor(int,int,long,TimeUnit,BlockingQueue,ThreadFactory)*
310 public ThreadPoolExecutor(
314 java.util.concurrent.TimeUnit unit,
315 java.util.concurrent.BlockingQueue workQueue,
316 java.util.concurrent.ThreadFactory threadFactory)
318 Creates a new ThreadPoolExecutor with the given initial parameters.
320 corePoolSize - the number of threads to keep in the pool, even if they are idle.
321 maximumPoolSize - the maximum number of threads to allow in the pool.
322 keepAliveTime - when the number of threads is greater than the core, this is the maximum time
323 that excess idle threads will wait for new tasks before terminating.
324 unit - the time unit for the keepAliveTime argument.
325 workQueue - the queue to use for holding tasks before they are executed. This queue will
326 hold only the Runnable tasks submitted by the execute method.
327 threadFactory - the factory to use when the executor creates a new thread.
329 *java.util.concurrent.ThreadPoolExecutor(int,int,long,TimeUnit,BlockingQueue,ThreadFactory,RejectedExecutionHandler)*
331 public ThreadPoolExecutor(
335 java.util.concurrent.TimeUnit unit,
336 java.util.concurrent.BlockingQueue workQueue,
337 java.util.concurrent.ThreadFactory threadFactory,
338 java.util.concurrent.RejectedExecutionHandler handler)
340 Creates a new ThreadPoolExecutor with the given initial parameters.
342 corePoolSize - the number of threads to keep in the pool, even if they are idle.
343 maximumPoolSize - the maximum number of threads to allow in the pool.
344 keepAliveTime - when the number of threads is greater than the core, this is the maximum time
345 that excess idle threads will wait for new tasks before terminating.
346 unit - the time unit for the keepAliveTime argument.
347 workQueue - the queue to use for holding tasks before they are executed. This queue will
348 hold only the Runnable tasks submitted by the execute method.
349 threadFactory - the factory to use when the executor creates a new thread.
350 handler - the handler to use when execution is blocked because the thread bounds and
351 queue capacities are reached.
353 *java.util.concurrent.ThreadPoolExecutor.afterExecute(Runnable,Throwable)*
355 protected void afterExecute(
356 java.lang.Runnable r,
357 java.lang.Throwable t)
359 Method invoked upon completion of execution of the given Runnable. This method
360 is invoked by the thread that executed the task. If non-null, the Throwable is
361 the uncaught exception that caused execution to terminate abruptly. Note: To
362 properly nest multiple overridings, subclasses should generally invoke
363 super.afterExecute at the beginning of this method.
365 r - the runnable that has completed.
366 t - the exception that caused termination, or null if execution completed normally.
368 *java.util.concurrent.ThreadPoolExecutor.awaitTermination(long,TimeUnit)*
370 public boolean awaitTermination(
372 java.util.concurrent.TimeUnit unit)
373 throws |java.lang.InterruptedException|
378 *java.util.concurrent.ThreadPoolExecutor.beforeExecute(Thread,Runnable)*
380 protected void beforeExecute(
382 java.lang.Runnable r)
384 Method invoked prior to executing the given Runnable in the given thread. This
385 method is invoked by thread t that will execute task r, and may be used to
386 re-initialize ThreadLocals, or to perform logging. Note: To properly nest
387 multiple overridings, subclasses should generally invoke super.beforeExecute at
388 the end of this method.
390 t - the thread that will run task r.
391 r - the task that will be executed.
393 *java.util.concurrent.ThreadPoolExecutor.execute(Runnable)*
395 public void execute(java.lang.Runnable command)
397 Executes the given task sometime in the future. The task may execute in a new
398 thread or in an existing pooled thread.
400 If the task cannot be submitted for execution, either because this executor has
401 been shutdown or because its capacity has been reached, the task is handled by
402 the current RejectedExecutionHandler.
404 command - the task to execute
406 *java.util.concurrent.ThreadPoolExecutor.finalize()*
408 protected void finalize()
410 Invokes shutdown when this executor is no longer referenced.
413 *java.util.concurrent.ThreadPoolExecutor.getActiveCount()*
415 public int getActiveCount()
417 Returns the approximate number of threads that are actively executing tasks.
420 Returns: the number of threads
421 *java.util.concurrent.ThreadPoolExecutor.getCompletedTaskCount()*
423 public long getCompletedTaskCount()
425 Returns the approximate total number of tasks that have completed execution.
426 Because the states of tasks and threads may change dynamically during
427 computation, the returned value is only an approximation, but one that does not
428 ever decrease across successive calls.
431 Returns: the number of tasks
432 *java.util.concurrent.ThreadPoolExecutor.getCorePoolSize()*
434 public int getCorePoolSize()
436 Returns the core number of threads.
439 Returns: the core number of threads
440 *java.util.concurrent.ThreadPoolExecutor.getKeepAliveTime(TimeUnit)*
442 public long getKeepAliveTime(java.util.concurrent.TimeUnit unit)
444 Returns the thread keep-alive time, which is the amount of time which threads
445 in excess of the core pool size may remain idle before being terminated.
447 unit - the desired time unit of the result
449 Returns: the time limit
450 *java.util.concurrent.ThreadPoolExecutor.getLargestPoolSize()*
452 public int getLargestPoolSize()
454 Returns the largest number of threads that have ever simultaneously been in the
458 Returns: the number of threads
459 *java.util.concurrent.ThreadPoolExecutor.getMaximumPoolSize()*
461 public int getMaximumPoolSize()
463 Returns the maximum allowed number of threads.
466 Returns: the maximum allowed number of threads
467 *java.util.concurrent.ThreadPoolExecutor.getPoolSize()*
469 public int getPoolSize()
471 Returns the current number of threads in the pool.
474 Returns: the number of threads
475 *java.util.concurrent.ThreadPoolExecutor.getQueue()*
477 public |java.util.concurrent.BlockingQueue| getQueue()
479 Returns the task queue used by this executor. Access to the task queue is
480 intended primarily for debugging and monitoring. This queue may be in active
481 use. Retrieving the task queue does not prevent queued tasks from executing.
484 Returns: the task queue
485 *java.util.concurrent.ThreadPoolExecutor.getRejectedExecutionHandler()*
487 public |java.util.concurrent.RejectedExecutionHandler| getRejectedExecutionHandler()
489 Returns the current handler for unexecutable tasks.
492 Returns: the current handler
493 *java.util.concurrent.ThreadPoolExecutor.getTaskCount()*
495 public long getTaskCount()
497 Returns the approximate total number of tasks that have been scheduled for
498 execution. Because the states of tasks and threads may change dynamically
499 during computation, the returned value is only an approximation, but one that
500 does not ever decrease across successive calls.
503 Returns: the number of tasks
504 *java.util.concurrent.ThreadPoolExecutor.getThreadFactory()*
506 public |java.util.concurrent.ThreadFactory| getThreadFactory()
508 Returns the thread factory used to create new threads.
511 Returns: the current thread factory
512 *java.util.concurrent.ThreadPoolExecutor.isShutdown()*
514 public boolean isShutdown()
519 *java.util.concurrent.ThreadPoolExecutor.isTerminated()*
521 public boolean isTerminated()
526 *java.util.concurrent.ThreadPoolExecutor.isTerminating()*
528 public boolean isTerminating()
530 Returns true if this executor is in the process of terminating after shutdown
531 or shutdownNow but has not completely terminated. This method may be useful for
532 debugging. A return of true reported a sufficient period after shutdown may
533 indicate that submitted tasks have ignored or suppressed interruption, causing
534 this executor not to properly terminate.
537 Returns: true if terminating but not yet terminated.
538 *java.util.concurrent.ThreadPoolExecutor.prestartAllCoreThreads()*
540 public int prestartAllCoreThreads()
542 Starts all core threads, causing them to idly wait for work. This overrides the
543 default policy of starting core threads only when new tasks are executed.
546 Returns: the number of threads started.
547 *java.util.concurrent.ThreadPoolExecutor.prestartCoreThread()*
549 public boolean prestartCoreThread()
551 Starts a core thread, causing it to idly wait for work. This overrides the
552 default policy of starting core threads only when new tasks are executed. This
553 method will return false if all core threads have already been started.
556 Returns: true if a thread was started
557 *java.util.concurrent.ThreadPoolExecutor.purge()*
561 Tries to remove from the work queue all (|java.util.concurrent.Future|) tasks
562 that have been cancelled. This method can be useful as a storage reclamation
563 operation, that has no other impact on functionality. Cancelled tasks are never
564 executed, but may accumulate in work queues until worker threads can actively
565 remove them. Invoking this method instead tries to remove them now. However,
566 this method may fail to remove tasks in the presence of interference by other
570 *java.util.concurrent.ThreadPoolExecutor.remove(Runnable)*
572 public boolean remove(java.lang.Runnable task)
574 Removes this task from the executor's internal queue if it is present, thus
575 causing it not to be run if it has not already started.
577 This method may be useful as one part of a cancellation scheme. It may fail to
578 remove tasks that have been converted into other forms before being placed on
579 the internal queue. For example, a task entered using submit might be converted
580 into a form that maintains Future status. However, in such cases, method
581 (|java.util.concurrent.ThreadPoolExecutor|) may be used to remove those Futures
582 that have been cancelled.
584 task - the task to remove
586 Returns: true if the task was removed
587 *java.util.concurrent.ThreadPoolExecutor.setCorePoolSize(int)*
589 public void setCorePoolSize(int corePoolSize)
591 Sets the core number of threads. This overrides any value set in the
592 constructor. If the new value is smaller than the current value, excess
593 existing threads will be terminated when they next become idle. If larger, new
594 threads will, if needed, be started to execute any queued tasks.
596 corePoolSize - the new core size
598 *java.util.concurrent.ThreadPoolExecutor.setKeepAliveTime(long,TimeUnit)*
600 public void setKeepAliveTime(
602 java.util.concurrent.TimeUnit unit)
604 Sets the time limit for which threads may remain idle before being terminated.
605 If there are more than the core number of threads currently in the pool, after
606 waiting this amount of time without processing a task, excess threads will be
607 terminated. This overrides any value set in the constructor.
609 time - the time to wait. A time value of zero will cause excess threads to terminate
610 immediately after executing tasks.
611 unit - the time unit of the time argument
613 *java.util.concurrent.ThreadPoolExecutor.setMaximumPoolSize(int)*
615 public void setMaximumPoolSize(int maximumPoolSize)
617 Sets the maximum allowed number of threads. This overrides any value set in the
618 constructor. If the new value is smaller than the current value, excess
619 existing threads will be terminated when they next become idle.
621 maximumPoolSize - the new maximum
623 *java.util.concurrent.ThreadPoolExecutor.setRejectedExecutionHandler(RejectedExecutionHandler)*
625 public void setRejectedExecutionHandler(java.util.concurrent.RejectedExecutionHandler handler)
627 Sets a new handler for unexecutable tasks.
629 handler - the new handler
631 *java.util.concurrent.ThreadPoolExecutor.setThreadFactory(ThreadFactory)*
633 public void setThreadFactory(java.util.concurrent.ThreadFactory threadFactory)
635 Sets the thread factory used to create new threads.
637 threadFactory - the new thread factory
639 *java.util.concurrent.ThreadPoolExecutor.shutdown()*
641 public void shutdown()
643 Initiates an orderly shutdown in which previously submitted tasks are executed,
644 but no new tasks will be accepted. Invocation has no additional effect if
648 *java.util.concurrent.ThreadPoolExecutor.shutdownNow()*
650 public |java.util.List| shutdownNow()
652 Attempts to stop all actively executing tasks, halts the processing of waiting
653 tasks, and returns a list of the tasks that were awaiting execution.
655 This implementation cancels tasks via (|java.lang.Thread|) , so if any tasks
656 mask or fail to respond to interrupts, they may never terminate.
659 Returns: list of tasks that never commenced execution
660 *java.util.concurrent.ThreadPoolExecutor.terminated()*
662 protected void terminated()
664 Method invoked when the Executor has terminated. Default implementation does
665 nothing. Note: To properly nest multiple overridings, subclasses should
666 generally invoke super.terminated within this method.