References Deprecated
AsyncListenableTaskExecutor is deprecated or references (maybe indirectly) at least one deprecated element.
See corresponding docs for further information.
java.util.concurrent.ThreadPoolExecutor
in bean style (through its "corePoolSize", "maxPoolSize", "keepAliveSeconds", "queueCapacity"
properties) and exposing it as a Spring org.springframework.core.task.TaskExecutor .
This class is also well suited for management and monitoring (e.g. through JMX),
providing several useful attributes: "corePoolSize", "maxPoolSize", "keepAliveSeconds"
(all supporting updates at runtime); "poolSize", "activeCount" (for introspection only).
The default configuration is a core pool size of 1, with unlimited max pool size
and unlimited queue capacity. This is roughly equivalent to
java., sharing a single
thread for all tasks. Setting "queueCapacity" to 0 mimics
java., with immediate scaling
of threads in the pool to a potentially very high number. Consider also setting a
"maxPoolSize" at that point, as well as possibly a higher
"corePoolSize" (see also the
"allowCoreThreadTimeOut" mode of scaling).
Note
This class implements Spring's
org. interface as well as the
java. interface, with the former being the primary
interface, the other just serving as secondary convenience. For this reason, the
exception handling follows the TaskExecutor contract rather than the Executor contract,
in particular regarding the org..
For an alternative, you may set up a ThreadPoolExecutor instance directly using
constructor injection, or use a factory method definition that points to the
java. class. To expose such a raw Executor as a
Spring org., simply wrap it with a
org. adapter.
org.springframework.core.task.TaskExecutor , java.util.concurrent.ThreadPoolExecutor , ThreadPoolExecutorFactoryBean, ConcurrentTaskExecutor
| Modifier and Type | Field and Description |
|---|---|
| private boolean | |
| private int | |
| private final Map | |
| private int | |
| private int | |
| private final Object | |
| private boolean | |
| private int | |
| private boolean | |
| private TaskDecorator | |
| private ThreadPoolExecutor |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected void | cancelRemainingTask(Runnable
the task to cancel (typically a task)RunnableFuture)Overrides org. Cancel the given remaining task which never commenced execution,
as returned from |
| protected BlockingQueue | Returns: the BlockingQueue instancethe specified queue capacity queueCapacity)Create the BlockingQueue to use for the ThreadPoolExecutor. |
| public void | execute(Runnable
the task)Runnable to execute (never null)Implements org. Execute the given |
| public int | |
| public int | |
| public int | |
| public int | |
| public int | |
| public int | |
| public int | |
| public ThreadPoolExecutor | Returns: the underlying ThreadPoolExecutor (nevernull)Return the underlying ThreadPoolExecutor for native access. |
| protected ExecutorService | initializeExecutor(ThreadFactory
the ThreadFactory to use threadFactory, RejectedExecutionHandler the RejectedExecutionHandler to use rejectedExecutionHandler)Implements abstract org. Note This method exposes an |
| protected void | initiateEarlyShutdown()
Overrides org. Early shutdown signal: do not trigger further tasks, let existing tasks complete
before hitting the actual destruction step in the |
| public void | setAllowCoreThreadTimeOut(boolean allowCoreThreadTimeOut)
Specify whether to allow core threads to time out. |
| public void | |
| public void | |
| public void | |
| public void | setPrestartAllCoreThreads(boolean prestartAllCoreThreads)
Specify whether to start all core threads, causing them to idly wait for work. |
| public void | |
| public void | setStrictEarlyShutdown(boolean defaultEarlyShutdown)
Specify whether to initiate an early shutdown signal on context close, disposing all idle threads and rejecting further task submissions. |
| public void | setTaskDecorator(TaskDecorator taskDecorator)
Specify a custom |
| public Future | submit(Runnable
the task)Runnable to execute (never null)Overrides default org. Submit a Runnable task for execution, receiving a Future representing that task. |
| public <T> Future | submit(Callable<T>
the task)Callable to execute (never null)Overrides default org. Submit a Callable task for execution, receiving a Future representing that task. |
| public ListenableFuture | submitListenable(Runnable
the task)Runnable to execute (never null)Implements org.
References Deprecated
ListenableFuture is deprecated or references (maybe indirectly) at least one deprecated element.
Submit a |
| public <T> ListenableFuture | submitListenable(Callable<T>
the task)Callable to execute (never null)Implements org.
References Deprecated
ListenableFuture is deprecated or references (maybe indirectly) at least one deprecated element.
Submit a |
| allowCoreThreadTimeOut | back to summary |
|---|---|
| private boolean allowCoreThreadTimeOut | |
| corePoolSize | back to summary |
|---|---|
| private int corePoolSize | |
| decoratedTaskMap | back to summary |
|---|---|
| private final Map<Runnable, Object> decoratedTaskMap | |
| keepAliveSeconds | back to summary |
|---|---|
| private int keepAliveSeconds | |
| maxPoolSize | back to summary |
|---|---|
| private int maxPoolSize | |
| poolSizeMonitor | back to summary |
|---|---|
| private final Object poolSizeMonitor | |
| prestartAllCoreThreads | back to summary |
|---|---|
| private boolean prestartAllCoreThreads | |
| queueCapacity | back to summary |
|---|---|
| private int queueCapacity | |
| strictEarlyShutdown | back to summary |
|---|---|
| private boolean strictEarlyShutdown | |
| taskDecorator | back to summary |
|---|---|
| private TaskDecorator taskDecorator
| |
| threadPoolExecutor | back to summary |
|---|---|
| private ThreadPoolExecutor threadPoolExecutor
| |
| ThreadPoolTaskExecutor | back to summary |
|---|---|
| public ThreadPoolTaskExecutor() | |
| cancelRemainingTask | back to summary |
|---|---|
| protected void cancelRemainingTask(Runnable task) Overrides org. Doc from org. Cancel the given remaining task which never commenced execution,
as returned from
| |
| createQueue | back to summary |
|---|---|
| protected BlockingQueue Create the BlockingQueue to use for the ThreadPoolExecutor. A LinkedBlockingQueue instance will be created for a positive capacity value; a SynchronousQueue otherwise.
| |
| execute | back to summary |
|---|---|
| public void execute(Runnable task) Implements org. Doc from org. Execute the given The call might return immediately if the implementation uses an asynchronous execution strategy, or might block in the case of synchronous execution. | |
| getActiveCount | back to summary |
|---|---|
| public int getActiveCount() Return the number of currently active threads. | |
| getCorePoolSize | back to summary |
|---|---|
| public int getCorePoolSize() Return the ThreadPoolExecutor's core pool size. | |
| getKeepAliveSeconds | back to summary |
|---|---|
| public int getKeepAliveSeconds() Return the ThreadPoolExecutor's keep-alive seconds. | |
| getMaxPoolSize | back to summary |
|---|---|
| public int getMaxPoolSize() Return the ThreadPoolExecutor's maximum pool size. | |
| getPoolSize | back to summary |
|---|---|
| public int getPoolSize() Return the current pool size. | |
| getQueueCapacity | back to summary |
|---|---|
| public int getQueueCapacity() Return the capacity for the ThreadPoolExecutor's BlockingQueue.
| |
| getQueueSize | back to summary |
|---|---|
| public int getQueueSize() Return the current queue size.
| |
| getThreadPoolExecutor | back to summary |
|---|---|
| public ThreadPoolExecutor getThreadPoolExecutor() throws IllegalStateException Return the underlying ThreadPoolExecutor for native access.
| |
| initializeExecutor | back to summary |
|---|---|
| protected ExecutorService initializeExecutor(ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) Implements abstract org. Note This method exposes an
| |
| initiateEarlyShutdown | back to summary |
|---|---|
| protected void initiateEarlyShutdown() Overrides org. Doc from org. Early shutdown signal: do not trigger further tasks, let existing tasks complete
before hitting the actual destruction step in the Called from The default implementation calls
| |
| setAllowCoreThreadTimeOut | back to summary |
|---|---|
| public void setAllowCoreThreadTimeOut(boolean allowCoreThreadTimeOut) Specify whether to allow core threads to time out. This enables dynamic growing and shrinking even in combination with a non-zero queue (since the max pool size will only grow once the queue is full). Default is "false". | |
| setCorePoolSize | back to summary |
|---|---|
| public void setCorePoolSize(int corePoolSize) Set the ThreadPoolExecutor's core pool size. Default is 1. This setting can be modified at runtime, for example through JMX. | |
| setKeepAliveSeconds | back to summary |
|---|---|
| public void setKeepAliveSeconds(int keepAliveSeconds) Set the ThreadPoolExecutor's keep-alive seconds. Default is 60. This setting can be modified at runtime, for example through JMX. | |
| setMaxPoolSize | back to summary |
|---|---|
| public void setMaxPoolSize(int maxPoolSize) Set the ThreadPoolExecutor's maximum pool size.
Default is This setting can be modified at runtime, for example through JMX. | |
| setPrestartAllCoreThreads | back to summary |
|---|---|
| public void setPrestartAllCoreThreads(boolean prestartAllCoreThreads) Specify whether to start all core threads, causing them to idly wait for work. Default is "false", starting threads and adding them to the pool on demand.
| |
| setQueueCapacity | back to summary |
|---|---|
| public void setQueueCapacity(int queueCapacity) Set the capacity for the ThreadPoolExecutor's BlockingQueue. Default is Any positive value will lead to a LinkedBlockingQueue instance; any other value will lead to a SynchronousQueue instance. | |
| setStrictEarlyShutdown | back to summary |
|---|---|
| public void setStrictEarlyShutdown(boolean defaultEarlyShutdown) Specify whether to initiate an early shutdown signal on context close, disposing all idle threads and rejecting further task submissions. By default, existing tasks will be allowed to complete within the
coordinated lifecycle stop phase in any case. This setting just controls
whether an explicit As of 6.1.4, the default is "false", leniently allowing for late tasks
to arrive after context close, still participating in the lifecycle stop
phase. Note that this differs from Switch this to "true" for a strict early shutdown signal analogous to
the 6.1-established default behavior of
| |
| setTaskDecorator | back to summary |
|---|---|
| public void setTaskDecorator(TaskDecorator taskDecorator) Specify a custom Note that such a decorator is not necessarily being applied to the
user-supplied The primary use case is to set some execution context around the task's invocation, or to provide some monitoring/statistics for task execution. Note Exception handling in
| |
| submit | back to summary |
|---|---|
| public Future Overrides default org. Doc from org. Submit a Runnable task for execution, receiving a Future representing that task.
The Future will return a As of 6.1, this method comes with a default implementation that delegates
to | |
| submit | back to summary |
|---|---|
| public <T> Future Overrides default org. Doc from org. Submit a Callable task for execution, receiving a Future representing that task. The Future will return the Callable's result upon completion. As of 6.1, this method comes with a default implementation that delegates
to | |
| submitListenable | back to summary |
|---|---|
| public ListenableFuture Implements org. Doc from org. References Deprecated
See corresponding docs for further information. Submit a
| |
| submitListenable | back to summary |
|---|---|
| public <T> ListenableFuture Implements org. Doc from org. References Deprecated
See corresponding docs for further information. Submit a
| |