java.util.concurrent.ThreadPoolExecutor
in bean style (through its "corePoolSize", "maxPoolSize", "keepAliveSeconds",
"queueCapacity" properties) and exposing it as a bean reference of its native
java.util.concurrent.ExecutorService type.
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).
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.
This is strongly recommended in particular for common @Bean methods in
configuration classes, where this FactoryBean variant would force you to
return the FactoryBean type instead of the actual Executor type.
If you need a timing-based java.
instead, consider ScheduledExecutorFactoryBean.
java.util.concurrent.ExecutorService , java.util.concurrent.Executors , java.util.concurrent.ThreadPoolExecutor
| Modifier and Type | Field and Description |
|---|---|
| private boolean | |
| private int | |
| private ExecutorService | |
| private boolean | |
| private int | |
| private int | |
| private boolean | |
| private int | |
| private boolean |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected ThreadPoolExecutor | Returns: a new ThreadPoolExecutor instancethe specified core pool size corePoolSize, int the specified maximum pool size maxPoolSize, int the specified keep-alive time in seconds keepAliveSeconds, BlockingQueue<Runnable> the BlockingQueue to use queue, ThreadFactory the ThreadFactory to use threadFactory, RejectedExecutionHandler the RejectedExecutionHandler to use rejectedExecutionHandler)Create a new instance of |
| protected BlockingQueue | Returns: the BlockingQueue instancethe specified queue capacity queueCapacity)Create the BlockingQueue to use for the ThreadPoolExecutor. |
| public ExecutorService | getObject()
Implements org. |
| public Class | getObjectType()
Implements org. null if not known in advance.
|
| protected ExecutorService | initializeExecutor(ThreadFactory
the ThreadFactory to use threadFactory, RejectedExecutionHandler the RejectedExecutionHandler to use rejectedExecutionHandler)Implements abstract org. java. instance.
|
| protected void | initiateEarlyShutdown()
Overrides org. shutdown() method.
|
| public boolean | isSingleton()
Overrides default org. |
| public void | setAllowCoreThreadTimeOut(boolean allowCoreThreadTimeOut)
Specify whether to allow core threads to time out. |
| public void | |
| public void | setExposeUnconfigurableExecutor(boolean exposeUnconfigurableExecutor)
Specify whether this FactoryBean should expose an unconfigurable decorator for the created executor. |
| 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. |
| allowCoreThreadTimeOut | back to summary |
|---|---|
| private boolean allowCoreThreadTimeOut | |
| corePoolSize | back to summary |
|---|---|
| private int corePoolSize | |
| exposedExecutor | back to summary |
|---|---|
| private ExecutorService exposedExecutor
| |
| exposeUnconfigurableExecutor | back to summary |
|---|---|
| private boolean exposeUnconfigurableExecutor | |
| keepAliveSeconds | back to summary |
|---|---|
| private int keepAliveSeconds | |
| maxPoolSize | back to summary |
|---|---|
| private int maxPoolSize | |
| prestartAllCoreThreads | back to summary |
|---|---|
| private boolean prestartAllCoreThreads | |
| queueCapacity | back to summary |
|---|---|
| private int queueCapacity | |
| strictEarlyShutdown | back to summary |
|---|---|
| private boolean strictEarlyShutdown | |
| ThreadPoolExecutorFactoryBean | back to summary |
|---|---|
| public ThreadPoolExecutorFactoryBean() | |
| createExecutor | back to summary |
|---|---|
| protected ThreadPoolExecutor createExecutor(int corePoolSize, int maxPoolSize, int keepAliveSeconds, BlockingQueue<Runnable> queue, ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) Create a new instance of The default implementation creates a standard
| |
| 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 else.
| |
| getObject | back to summary |
|---|---|
| public ExecutorService getObject() Implements org. Doc from org. Return an instance (possibly shared or independent) of the object managed by this factory. As with a If this FactoryBean is not fully initialized yet at the time of
the call (for example because it is involved in a circular reference),
throw a corresponding As of Spring 2.0, FactoryBeans are allowed to return
| |
| getObjectType | back to summary |
|---|---|
| public Class Implements org. Doc from org. Return the type of object that this FactoryBean creates,
or This allows one to check for specific types of beans without instantiating objects, for example on autowiring. In the case of implementations that are creating a singleton object, this method should try to avoid singleton creation as far as possible; it should rather estimate the type in advance. For prototypes, returning a meaningful type here is advisable too. This method can be called before this FactoryBean has been fully initialized. It must not rely on state created during initialization; of course, it can still use such state if available. Note Autowiring will simply ignore FactoryBeans that return
| |
| initializeExecutor | back to summary |
|---|---|
| protected ExecutorService initializeExecutor(ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) Implements abstract org. Doc from org. Create the target
| |
| 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
| |
| isSingleton | back to summary |
|---|---|
| public boolean isSingleton() Overrides default org. Doc from org. Is the object managed by this factory a singleton? That is,
will Note If a FactoryBean indicates to hold a singleton object,
the object returned from The singleton status of the FactoryBean itself will generally be provided by the owning BeanFactory; usually, it has to be defined as singleton there. Note This method returning The default implementation returns
| |
| 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. | |
| setExposeUnconfigurableExecutor | back to summary |
|---|---|
| public void setExposeUnconfigurableExecutor(boolean exposeUnconfigurableExecutor) Specify whether this FactoryBean should expose an unconfigurable decorator for the created executor. Default is "false", exposing the raw executor as bean reference. Switch this flag to "true" to strictly prevent clients from modifying the executor's configuration. | |
| setKeepAliveSeconds | back to summary |
|---|---|
| public void setKeepAliveSeconds(int keepAliveSeconds) Set the ThreadPoolExecutor's keep-alive seconds. Default is 60. | |
| setMaxPoolSize | back to summary |
|---|---|
| public void setMaxPoolSize(int maxPoolSize) Set the ThreadPoolExecutor's maximum pool size.
Default is | |
| 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".
| |
| 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. Default is "false".
See
| |