java.lang.Object | ||||
↳ | org.springframework.util.CustomizableThreadCreator | |||
↳ | org.springframework.scheduling.concurrent.CustomizableThreadFactory | |||
↳ | org.springframework.scheduling.concurrent.ExecutorConfigurationSupport | |||
↳ | org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor |
JavaBean that allows for configuring a JDK 1.5 java.util.concurrent.ThreadPoolExecutor
in bean style (through its "corePoolSize", "maxPoolSize", "keepAliveSeconds", "queueCapacity"
properties) and exposing it as a Spring 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).
For an alternative, you may set up a ThreadPoolExecutor instance directly using
constructor injection, or use a factory method definition that points to the JDK 1.5
java.util.concurrent.Executors class. To expose such a raw Executor as a
Spring TaskExecutor
, simply wrap it with a
ConcurrentTaskExecutor
adapter.
NOTE: This class implements Spring's
TaskExecutor
interface as well as the JDK 1.5
Executor
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 TaskRejectedException
.
If you prefer native ExecutorService
exposure instead,
consider ThreadPoolExecutorFactoryBean
as an alternative to this class.
TaskExecutor
ConcurrentTaskExecutor
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From interface
org.springframework.core.task.AsyncTaskExecutor
|
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.scheduling.concurrent.ExecutorConfigurationSupport
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Execute the given
task . | |||||||||||
Execute the given
task . | |||||||||||
Return the number of currently active threads.
| |||||||||||
Return the ThreadPoolExecutor's core pool size.
| |||||||||||
Return the ThreadPoolExecutor's keep-alive seconds.
| |||||||||||
Return the ThreadPoolExecutor's maximum pool size.
| |||||||||||
Return the current pool size.
| |||||||||||
Return the underlying ThreadPoolExecutor for native access.
| |||||||||||
This task executor prefers short-lived work units.
| |||||||||||
Specify whether to allow core threads to time out.
| |||||||||||
Set the ThreadPoolExecutor's core pool size.
| |||||||||||
Set the ThreadPoolExecutor's keep-alive seconds.
| |||||||||||
Set the ThreadPoolExecutor's maximum pool size.
| |||||||||||
Set the capacity for the ThreadPoolExecutor's BlockingQueue.
| |||||||||||
Submit a Callable task for execution, receiving a Future representing that task.
| |||||||||||
Submit a Runnable task for execution, receiving a Future representing that task.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create the BlockingQueue to use for the ThreadPoolExecutor.
| |||||||||||
Create the target
ExecutorService instance. |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.scheduling.concurrent.ExecutorConfigurationSupport
| |||||||||||
From class
org.springframework.scheduling.concurrent.CustomizableThreadFactory
| |||||||||||
From class
org.springframework.util.CustomizableThreadCreator
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
java.util.concurrent.Executor
| |||||||||||
From interface
java.util.concurrent.ThreadFactory
| |||||||||||
From interface
org.springframework.beans.factory.BeanNameAware
| |||||||||||
From interface
org.springframework.beans.factory.DisposableBean
| |||||||||||
From interface
org.springframework.beans.factory.InitializingBean
| |||||||||||
From interface
org.springframework.core.task.AsyncTaskExecutor
| |||||||||||
From interface
org.springframework.core.task.TaskExecutor
| |||||||||||
From interface
org.springframework.scheduling.SchedulingTaskExecutor
|
Execute the given task
.
task | the Runnable to execute (never null ) |
---|---|
startTimeout | the time duration (milliseconds) within which the task is
supposed to start. This is intended as a hint to the executor, allowing for
preferred handling of immediate tasks. Typical values are TIMEOUT_IMMEDIATE
or TIMEOUT_INDEFINITE (the default as used by execute(Runnable) ). |
Execute the given task
.
The call might return immediately if the implementation uses an asynchronous execution strategy, or might block in the case of synchronous execution.
task | the Runnable to execute (never null ) |
---|
Return the number of currently active threads.
Return the ThreadPoolExecutor's core pool size.
Return the ThreadPoolExecutor's keep-alive seconds.
Return the ThreadPoolExecutor's maximum pool size.
Return the underlying ThreadPoolExecutor for native access.
null
)IllegalStateException | if the ThreadPoolTaskExecutor hasn't been initialized yet |
---|
This task executor prefers short-lived work units.
true
if this TaskExecutor
prefers
short-lived tasks
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". Note that this feature is only available on Java 6 or above. On Java 5, consider switching to the backport-concurrent version of ThreadPoolTaskExecutor which also supports this feature.
Set the ThreadPoolExecutor's core pool size. Default is 1.
This setting can be modified at runtime, for example through JMX.
Set the ThreadPoolExecutor's keep-alive seconds. Default is 60.
This setting can be modified at runtime, for example through JMX.
Set the ThreadPoolExecutor's maximum pool size.
Default is Integer.MAX_VALUE
.
This setting can be modified at runtime, for example through JMX.
Set the capacity for the ThreadPoolExecutor's BlockingQueue.
Default is Integer.MAX_VALUE
.
Any positive value will lead to a LinkedBlockingQueue instance; any other value will lead to a SynchronousQueue instance.
Submit a Callable task for execution, receiving a Future representing that task. The Future will return the Callable's result upon completion.
task | the Callable to execute (never null ) |
---|
Submit a Runnable task for execution, receiving a Future representing that task.
The Future will return a null
result upon completion.
task | the Runnable to execute (never null ) |
---|
Create the BlockingQueue to use for the ThreadPoolExecutor.
A LinkedBlockingQueue instance will be created for a positive capacity value; a SynchronousQueue else.
queueCapacity | the specified queue capacity |
---|
Create the target ExecutorService
instance.
Called by afterPropertiesSet
.
threadFactory | the ThreadFactory to use |
---|---|
rejectedExecutionHandler | the RejectedExecutionHandler to use |