spring-framework / org.springframework.scheduling.concurrent / ThreadPoolExecutorFactoryBean

ThreadPoolExecutorFactoryBean

open class ThreadPoolExecutorFactoryBean : ExecutorConfigurationSupport, FactoryBean<ExecutorService>, InitializingBean, DisposableBean

JavaBean that allows for configuring a 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.

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.util.concurrent.Executors 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.util.concurrent.ScheduledExecutorService instead, consider ScheduledExecutorFactoryBean.

Author
Juergen Hoeller

Since
3.0

See Also
java.util.concurrent.ExecutorServicejava.util.concurrent.Executorsjava.util.concurrent.ThreadPoolExecutor

Constructors

<init>

ThreadPoolExecutorFactoryBean()

JavaBean that allows for configuring a 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.

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.util.concurrent.Executors 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.util.concurrent.ScheduledExecutorService instead, consider ScheduledExecutorFactoryBean.

Functions

getObject

open fun getObject(): ExecutorService

getObjectType

open fun getObjectType(): Class<out ExecutorService>

isSingleton

open fun isSingleton(): Boolean

setAllowCoreThreadTimeOut

open fun setAllowCoreThreadTimeOut(allowCoreThreadTimeOut: Boolean): Unit

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

open fun setCorePoolSize(corePoolSize: Int): Unit

Set the ThreadPoolExecutor's core pool size. Default is 1.

setExposeUnconfigurableExecutor

open fun setExposeUnconfigurableExecutor(exposeUnconfigurableExecutor: Boolean): Unit

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

open fun setKeepAliveSeconds(keepAliveSeconds: Int): Unit

Set the ThreadPoolExecutor's keep-alive seconds. Default is 60.

setMaxPoolSize

open fun setMaxPoolSize(maxPoolSize: Int): Unit

Set the ThreadPoolExecutor's maximum pool size. Default is Integer.MAX_VALUE.

setQueueCapacity

open fun setQueueCapacity(queueCapacity: Int): Unit

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.