Class 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:

    Author:
    Derek Hulley
    • Constructor Detail

      • ThreadPoolExecutorFactoryBean

        public ThreadPoolExecutorFactoryBean()
        Constructor setting default properties:
    • 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​(RejectedExecutionHandler rejectedExecutionHandler)
        The optional handler for when tasks cannot be submitted to the queue. The default is the CallerRunsPolicy.
        Parameters:
        rejectedExecutionHandler - the handler to use
      • afterPropertiesSet

        public void afterPropertiesSet()
                                throws Exception
        Specified by:
        afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
        Throws:
        Exception
      • isSingleton

        public boolean isSingleton()
        Specified by:
        isSingleton in interface org.springframework.beans.factory.FactoryBean
        Returns:
        Returns true always.
      • getObject

        public Object getObject()
                         throws Exception
        Specified by:
        getObject in interface org.springframework.beans.factory.FactoryBean
        Returns:
        Returns the singleton instance.
        Throws:
        Exception
      • getObjectType

        public Class getObjectType()
        Specified by:
        getObjectType in interface org.springframework.beans.factory.FactoryBean
        See Also:
        ThreadPoolExecutor
      • getPoolName

        public String getPoolName()
      • setPoolName

        public void setPoolName​(String poolName)
      • destroy

        public void destroy()
        Specified by:
        destroy in interface org.springframework.beans.factory.DisposableBean