Package org.alfresco.util
Class ThreadPoolExecutorFactoryBean
java.lang.Object
org.alfresco.util.ThreadPoolExecutorFactoryBean
- All Implemented Interfaces:
org.springframework.beans.factory.DisposableBean,org.springframework.beans.factory.FactoryBean,org.springframework.beans.factory.InitializingBean
public class ThreadPoolExecutorFactoryBean
extends Object
implements org.springframework.beans.factory.FactoryBean, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean
Factory for
ThreadPoolExecutor instances, which cannot easily be constructed using constructor injection. This instance also allows the setting of the thread-specific properties that would otherwise require setting a ThreadFactory.
This factory provides the a singleton instance of the pool.
Defaults are:
corePoolSize: 20maximumPoolSize: Equal to thesetCorePoolSize(int)at the time of instance creationkeepAliveTime: 90 secondsthreadPriority: 5 (NORM)threadDaemon: trueworkQueueSize: -1 or less (No upper bound)rejectedExecutionHandler:ThreadPoolExecutor.CallerRunsPolicy
- Author:
- Derek Hulley
-
Field Summary
Fields inherited from interface org.springframework.beans.factory.FactoryBean
OBJECT_TYPE_ATTRIBUTE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoiddestroy()booleanvoidsetCorePoolSize(int corePoolSize) The number of threads to keep in the pool, even if idle.voidsetKeepAliveTime(int keepAliveTime) The time (in seconds) to keep non-core idle threads in the poolvoidsetMaximumPoolSize(int maximumPoolSize) The maximum number of threads to keep in the poolvoidsetPoolName(String poolName) voidsetRejectedExecutionHandler(RejectedExecutionHandler rejectedExecutionHandler) The optional handler for when tasks cannot be submitted to the queue.voidsetThreadDaemon(boolean threadDaemon) Set whether the threads run as daemon threads or not.voidsetThreadPriority(int threadPriority) The priority that all threads must have on the scale of 1 to 10, where 1 has the lowest priority and 10 has the highest priority.voidsetWorkQueueSize(int workQueueSize) The maximum number of queued work instances to keep before blocking against further adds.
-
Constructor Details
-
ThreadPoolExecutorFactoryBean
public ThreadPoolExecutorFactoryBean()Constructor setting default properties:
-
-
Method Details
-
setCorePoolSize
public void setCorePoolSize(int corePoolSize) The number of threads to keep in the pool, even if idle.- Parameters:
corePoolSize- core thread count
-
setMaximumPoolSize
public void setMaximumPoolSize(int maximumPoolSize) The maximum number of threads to keep in the pool- Parameters:
maximumPoolSize- the maximum number of threads in the pool
-
setKeepAliveTime
public void setKeepAliveTime(int keepAliveTime) The time (in seconds) to keep non-core idle threads in the pool- Parameters:
keepAliveTime- time to stay idle in seconds
-
setThreadPriority
public void setThreadPriority(int threadPriority) The priority that all threads must have on the scale of 1 to 10, where 1 has the lowest priority and 10 has the highest priority.- Parameters:
threadPriority- the thread priority
-
setThreadDaemon
public void setThreadDaemon(boolean threadDaemon) Set whether the threads run as daemon threads or not.- Parameters:
threadDaemon- true to run as daemon
-
setWorkQueueSize
public void setWorkQueueSize(int workQueueSize) The maximum number of queued work instances to keep before blocking against further adds.- Parameters:
workQueueSize- the queue size before blocks, or -1 default to indicate no upper bound
-
setRejectedExecutionHandler
The optional handler for when tasks cannot be submitted to the queue. The default is theCallerRunsPolicy.- Parameters:
rejectedExecutionHandler- the handler to use
-
afterPropertiesSet
- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
Exception
-
isSingleton
public boolean isSingleton()- Specified by:
isSingletonin interfaceorg.springframework.beans.factory.FactoryBean- Returns:
- Returns true always.
-
getObject
-
getObjectType
- Specified by:
getObjectTypein interfaceorg.springframework.beans.factory.FactoryBean- See Also:
-
getPoolName
-
setPoolName
-
destroy
public void destroy()- Specified by:
destroyin interfaceorg.springframework.beans.factory.DisposableBean
-