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 java.lang.Object implements org.springframework.beans.factory.FactoryBean, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBeanFactory forThreadPoolExecutorinstances, which cannot easily be constructed using constructor injection. This instance also allows the setting of the thread-specific properties that would otherwise require setting aThreadFactory.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
-
-
Constructor Summary
Constructors Constructor Description ThreadPoolExecutorFactoryBean()Constructor setting default properties:
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterPropertiesSet()voiddestroy()java.lang.ObjectgetObject()java.lang.ClassgetObjectType()java.lang.StringgetPoolName()booleanisSingleton()voidsetCorePoolSize(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(java.lang.String poolName)voidsetRejectedExecutionHandler(java.util.concurrent.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.
-
-
-
Method Detail
-
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
public void setRejectedExecutionHandler(java.util.concurrent.RejectedExecutionHandler rejectedExecutionHandler)
The optional handler for when tasks cannot be submitted to the queue. The default is theCallerRunsPolicy.- Parameters:
rejectedExecutionHandler- the handler to use
-
afterPropertiesSet
public void afterPropertiesSet() throws java.lang.Exception- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
java.lang.Exception
-
isSingleton
public boolean isSingleton()
- Specified by:
isSingletonin interfaceorg.springframework.beans.factory.FactoryBean- Returns:
- Returns true always.
-
getObject
public java.lang.Object getObject() throws java.lang.Exception- Specified by:
getObjectin interfaceorg.springframework.beans.factory.FactoryBean- Returns:
- Returns the singleton
instance. - Throws:
java.lang.Exception
-
getObjectType
public java.lang.Class getObjectType()
- Specified by:
getObjectTypein interfaceorg.springframework.beans.factory.FactoryBean- See Also:
ThreadPoolExecutor
-
getPoolName
public java.lang.String getPoolName()
-
setPoolName
public void setPoolName(java.lang.String poolName)
-
destroy
public void destroy()
- Specified by:
destroyin interfaceorg.springframework.beans.factory.DisposableBean
-
-