Package org.springframework.boot.task
Class ThreadPoolTaskExecutorBuilder
java.lang.Object
org.springframework.boot.task.ThreadPoolTaskExecutorBuilder
Builder that can be used to configure and create a 
ThreadPoolTaskExecutor.
 Provides convenience methods to set common ThreadPoolTaskExecutor settings and
 register taskDecorator(TaskDecorator)). For advanced configuration, consider
 using ThreadPoolTaskExecutorCustomizer.
 
 In a typical auto-configured Spring Boot application this builder is available as a
 bean and can be injected whenever a ThreadPoolTaskExecutor is needed.
- Since:
- 3.2.0
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionacceptTasksAfterContextClose(boolean acceptTasksAfterContextClose) Set whether to accept further tasks after the application context close phase has begun.additionalCustomizers(Iterable<? extends ThreadPoolTaskExecutorCustomizer> customizers) AddThreadPoolTaskExecutorCustomizersthat should be applied to theThreadPoolTaskExecutor.additionalCustomizers(ThreadPoolTaskExecutorCustomizer... customizers) AddThreadPoolTaskExecutorCustomizersthat should be applied to theThreadPoolTaskExecutor.allowCoreThreadTimeOut(boolean allowCoreThreadTimeOut) Set whether core threads are allowed to time out.awaitTermination(boolean awaitTermination) Set whether the executor should wait for scheduled tasks to complete on shutdown, not interrupting running tasks and executing all tasks in the queue.awaitTerminationPeriod(Duration awaitTerminationPeriod) Set the maximum time the executor is supposed to block on shutdown.org.springframework.scheduling.concurrent.ThreadPoolTaskExecutorbuild()Build a newThreadPoolTaskExecutorinstance and configure it using this builder.<T extends org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor>
 TBuild a newThreadPoolTaskExecutorinstance of the specified type and configure it using this builder.<T extends org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor>
 Tconfigure(T taskExecutor) Configure the providedThreadPoolTaskExecutorinstance using this builder.corePoolSize(int corePoolSize) Set the core number of threads.customizers(Iterable<? extends ThreadPoolTaskExecutorCustomizer> customizers) Set theThreadPoolTaskExecutorCustomizersthat should be applied to theThreadPoolTaskExecutor.customizers(ThreadPoolTaskExecutorCustomizer... customizers) Set theThreadPoolTaskExecutorCustomizersthat should be applied to theThreadPoolTaskExecutor.Set the time limit for which threads may remain idle before being terminated.maxPoolSize(int maxPoolSize) Set the maximum allowed number of threads.queueCapacity(int queueCapacity) Set the capacity of the queue.taskDecorator(org.springframework.core.task.TaskDecorator taskDecorator) Set theTaskDecoratorto use ornullto not use any.threadNamePrefix(String threadNamePrefix) Set the prefix to use for the names of newly created threads.
- 
Constructor Details- 
ThreadPoolTaskExecutorBuilderpublic ThreadPoolTaskExecutorBuilder()
 
- 
- 
Method Details- 
queueCapacitySet the capacity of the queue. An unbounded capacity does not increase the pool and therefore ignoresmaxPoolSize.- Parameters:
- queueCapacity- the queue capacity to set
- Returns:
- a new builder instance
 
- 
corePoolSizeSet the core number of threads. Effectively that maximum number of threads as long as the queue is not full.Core threads can grow and shrink if allowCoreThreadTimeOut(boolean)is enabled.- Parameters:
- corePoolSize- the core pool size to set
- Returns:
- a new builder instance
 
- 
maxPoolSizeSet the maximum allowed number of threads. When thequeueis full, the pool can expand up to that size to accommodate the load.If the queue capacityis unbounded, this setting is ignored.- Parameters:
- maxPoolSize- the max pool size to set
- Returns:
- a new builder instance
 
- 
allowCoreThreadTimeOutSet whether core threads are allowed to time out. When enabled, this enables dynamic growing and shrinking of the pool.- Parameters:
- allowCoreThreadTimeOut- if core threads are allowed to time out
- Returns:
- a new builder instance
 
- 
keepAliveSet the time limit for which threads may remain idle before being terminated.- Parameters:
- keepAlive- the keep alive to set
- Returns:
- a new builder instance
 
- 
acceptTasksAfterContextClosepublic ThreadPoolTaskExecutorBuilder acceptTasksAfterContextClose(boolean acceptTasksAfterContextClose) Set whether to accept further tasks after the application context close phase has begun.- Parameters:
- acceptTasksAfterContextClose- whether to accept further tasks after the application context close phase has begun
- Returns:
- a new builder instance
- Since:
- 3.3.0
 
- 
awaitTerminationSet whether the executor should wait for scheduled tasks to complete on shutdown, not interrupting running tasks and executing all tasks in the queue.- Parameters:
- awaitTermination- whether the executor needs to wait for the tasks to complete on shutdown
- Returns:
- a new builder instance
- See Also:
 
- 
awaitTerminationPeriodSet the maximum time the executor is supposed to block on shutdown. When set, the executor blocks on shutdown in order to wait for remaining tasks to complete their execution before the rest of the container continues to shut down. This is particularly useful if your remaining tasks are likely to need access to other resources that are also managed by the container.- Parameters:
- awaitTerminationPeriod- the await termination period to set
- Returns:
- a new builder instance
 
- 
threadNamePrefixSet the prefix to use for the names of newly created threads.- Parameters:
- threadNamePrefix- the thread name prefix to set
- Returns:
- a new builder instance
 
- 
taskDecoratorpublic ThreadPoolTaskExecutorBuilder taskDecorator(org.springframework.core.task.TaskDecorator taskDecorator) Set theTaskDecoratorto use ornullto not use any.- Parameters:
- taskDecorator- the task decorator to use
- Returns:
- a new builder instance
 
- 
customizersSet theThreadPoolTaskExecutorCustomizersthat should be applied to theThreadPoolTaskExecutor. Customizers are applied in the order that they were added after builder configuration has been applied. Setting this value will replace any previously configured customizers.- Parameters:
- customizers- the customizers to set
- Returns:
- a new builder instance
- See Also:
 
- 
customizerspublic ThreadPoolTaskExecutorBuilder customizers(Iterable<? extends ThreadPoolTaskExecutorCustomizer> customizers) Set theThreadPoolTaskExecutorCustomizersthat should be applied to theThreadPoolTaskExecutor. Customizers are applied in the order that they were added after builder configuration has been applied. Setting this value will replace any previously configured customizers.- Parameters:
- customizers- the customizers to set
- Returns:
- a new builder instance
- See Also:
 
- 
additionalCustomizerspublic ThreadPoolTaskExecutorBuilder additionalCustomizers(ThreadPoolTaskExecutorCustomizer... customizers) AddThreadPoolTaskExecutorCustomizersthat should be applied to theThreadPoolTaskExecutor. Customizers are applied in the order that they were added after builder configuration has been applied.- Parameters:
- customizers- the customizers to add
- Returns:
- a new builder instance
- See Also:
 
- 
additionalCustomizerspublic ThreadPoolTaskExecutorBuilder additionalCustomizers(Iterable<? extends ThreadPoolTaskExecutorCustomizer> customizers) AddThreadPoolTaskExecutorCustomizersthat should be applied to theThreadPoolTaskExecutor. Customizers are applied in the order that they were added after builder configuration has been applied.- Parameters:
- customizers- the customizers to add
- Returns:
- a new builder instance
- See Also:
 
- 
buildpublic org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor build()Build a newThreadPoolTaskExecutorinstance and configure it using this builder.- Returns:
- a configured ThreadPoolTaskExecutorinstance.
- See Also:
 
- 
buildpublic <T extends org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor> T build(Class<T> taskExecutorClass) Build a newThreadPoolTaskExecutorinstance of the specified type and configure it using this builder.- Type Parameters:
- T- the type of task executor
- Parameters:
- taskExecutorClass- the template type to create
- Returns:
- a configured ThreadPoolTaskExecutorinstance.
- See Also:
 
- 
configurepublic <T extends org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor> T configure(T taskExecutor) Configure the providedThreadPoolTaskExecutorinstance using this builder.- Type Parameters:
- T- the type of task executor
- Parameters:
- taskExecutor- the- ThreadPoolTaskExecutorto configure
- Returns:
- the task executor instance
- See Also:
 
 
-