java.lang.Object | |||
↳ | org.springframework.util.CustomizableThreadCreator | ||
↳ | org.springframework.scheduling.backportconcurrent.CustomizableThreadFactory | ||
↳ | org.springframework.scheduling.backportconcurrent.ThreadPoolTaskExecutor |
JavaBean that allows for configuring a JSR-166 backport
edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor in bean
style (through its "corePoolSize", "maxPoolSize", "keepAliveSeconds", "queueCapacity"
properties), exposing it as a Spring TaskExecutor
.
This is an alternative to configuring a ThreadPoolExecutor instance directly using
constructor injection, with a separate ConcurrentTaskExecutor
adapter wrapping it.
For any custom needs, in particular for defining a
edu.emory.mathcs.backport.java.util.concurrent.ScheduledThreadPoolExecutor,
it is recommended to use a straight definition of the Executor instance or a
factory method definition that points to the JSR-166 backport
edu.emory.mathcs.backport.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 (and hence implicitly
the standard Java 5 Executor
interface) as well as
the JSR-166 edu.emory.mathcs.backport.java.util.concurrent.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 backport Executor contract, in
particular regarding the TaskRejectedException
.
TaskExecutor
ConcurrentTaskExecutor
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From interface
org.springframework.core.task.AsyncTaskExecutor
|
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
logger |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Calls
initialize() after the container applied all property values. | |||||||||||
Calls
shutdown when the BeanFactory destroys
the task executor instance. | |||||||||||
Execute the given
task . | |||||||||||
Implementation of both the JSR-166 backport Executor interface and the Spring
TaskExecutor interface, delegating to the ThreadPoolExecutor instance.
| |||||||||||
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.
| |||||||||||
Creates the BlockingQueue and the ThreadPoolExecutor.
| |||||||||||
This task executor prefers short-lived work units.
| |||||||||||
Specify whether to allow core threads to time out.
| |||||||||||
Set the name of the bean in the bean factory that created this bean.
| |||||||||||
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.
| |||||||||||
Set the RejectedExecutionHandler to use for the ThreadPoolExecutor.
| |||||||||||
Set the ThreadFactory to use for the ThreadPoolExecutor's thread pool.
| |||||||||||
Specify the prefix to use for the names of newly created threads.
| |||||||||||
Set whether to wait for scheduled tasks to complete on shutdown.
| |||||||||||
Perform a shutdown on the ThreadPoolExecutor.
| |||||||||||
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.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.scheduling.backportconcurrent.CustomizableThreadFactory
| |||||||||||
From class
org.springframework.util.CustomizableThreadCreator
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
java.util.concurrent.Executor
| |||||||||||
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
|
Calls initialize()
after the container applied all property values.
Calls shutdown
when the BeanFactory destroys
the task executor instance.
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) ). |
Implementation of both the JSR-166 backport Executor interface and the Spring TaskExecutor interface, delegating to the ThreadPoolExecutor instance.
task | the Runnable to execute (never null ) |
---|
execute(Runnable)
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.
null
)IllegalStateException | if the ThreadPoolTaskExecutor hasn't been initialized yet |
---|
Creates the BlockingQueue and the ThreadPoolExecutor.
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 backport-concurrent 3.0 or above (based on the code in Java 6).
Set the name of the bean in the bean factory that created this bean.
Invoked after population of normal bean properties but before an
init callback such as afterPropertiesSet()
or a custom init-method.
name | the name of the bean in the factory. Note that this name is the actual bean name used in the factory, which may differ from the originally specified name: in particular for inner bean names, the actual bean name might have been made unique through appending "#..." suffixes. Use the BeanFactoryUtils#originalBeanName(String) method to extract the original bean name (without suffix), if desired. |
---|
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.
Set the RejectedExecutionHandler to use for the ThreadPoolExecutor. Default is the ThreadPoolExecutor's default abort policy.
Set the ThreadFactory to use for the ThreadPoolExecutor's thread pool.
Default is this executor itself (i.e. the factory that this executor
inherits from). See CustomizableThreadCreator
's
javadoc for available bean properties.
Specify the prefix to use for the names of newly created threads. Default is "SimpleAsyncTaskExecutor-".
Set whether to wait for scheduled tasks to complete on shutdown.
Default is "false". Switch this to "true" if you prefer fully completed tasks at the expense of a longer shutdown phase.
Perform a shutdown on the ThreadPoolExecutor.
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 |
---|