Class ThreadPoolExecutorFactoryBean

java.lang.Object
org.springframework.util.CustomizableThreadCreator
All Implemented Interfaces:
Serializable, ThreadFactory, EventListener, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.FactoryBean<ExecutorService>, org.springframework.beans.factory.InitializingBean, ApplicationContextAware, ApplicationListener<ContextClosedEvent>, Lifecycle, Phased, SmartLifecycle

public class ThreadPoolExecutorFactoryBean extends ExecutorConfigurationSupport implements org.springframework.beans.factory.FactoryBean<ExecutorService>
JavaBean that allows for configuring a ThreadPoolExecutor in bean style (through its "corePoolSize", "maxPoolSize", "keepAliveSeconds", "queueCapacity" properties) and exposing it as a bean reference of its native 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 Executors.newSingleThreadExecutor(), sharing a single thread for all tasks. Setting "queueCapacity" to 0 mimics Executors.newCachedThreadPool(), 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 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 ScheduledExecutorService instead, consider ScheduledExecutorFactoryBean.

Since:
3.0
Author:
Juergen Hoeller
See Also: