Package org.springframework.boot.task
Class ThreadPoolTaskSchedulerBuilder
java.lang.Object
org.springframework.boot.task.ThreadPoolTaskSchedulerBuilder
Builder that can be used to configure and create a 
ThreadPoolTaskScheduler.
 Provides convenience methods to set common ThreadPoolTaskScheduler settings.
 For advanced configuration, consider using ThreadPoolTaskSchedulerCustomizer.
 
 In a typical auto-configured Spring Boot application this builder is available as a
 bean and can be injected whenever a ThreadPoolTaskScheduler is needed.
- Since:
- 3.2.0
- 
Constructor SummaryConstructorsConstructorDescriptionThreadPoolTaskSchedulerBuilder(Integer poolSize, Boolean awaitTermination, Duration awaitTerminationPeriod, String threadNamePrefix, Set<ThreadPoolTaskSchedulerCustomizer> taskSchedulerCustomizers) Deprecated, for removal: This API element is subject to removal in a future version.since 3.5.0 for removal in 4.0.0 in favor of the default constructor
- 
Method SummaryModifier and TypeMethodDescriptionadditionalCustomizers(Iterable<? extends ThreadPoolTaskSchedulerCustomizer> customizers) AddthreadPoolTaskSchedulerCustomizersthat should be applied to theThreadPoolTaskScheduler.additionalCustomizers(ThreadPoolTaskSchedulerCustomizer... customizers) AddthreadPoolTaskSchedulerCustomizersthat should be applied to theThreadPoolTaskScheduler.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.ThreadPoolTaskSchedulerbuild()Build a newThreadPoolTaskSchedulerinstance and configure it using this builder.<T extends org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler>
 Tconfigure(T taskScheduler) Configure the providedThreadPoolTaskSchedulerinstance using this builder.customizers(Iterable<? extends ThreadPoolTaskSchedulerCustomizer> customizers) Set thethreadPoolTaskSchedulerCustomizersthat should be applied to theThreadPoolTaskScheduler.customizers(ThreadPoolTaskSchedulerCustomizer... customizers) Set thethreadPoolTaskSchedulerCustomizersthat should be applied to theThreadPoolTaskScheduler.poolSize(int poolSize) Set the maximum allowed number of threads.taskDecorator(org.springframework.core.task.TaskDecorator taskDecorator) Set theTaskDecoratorto be applied to theThreadPoolTaskScheduler.threadNamePrefix(String threadNamePrefix) Set the prefix to use for the names of newly created threads.
- 
Constructor Details- 
ThreadPoolTaskSchedulerBuilderpublic ThreadPoolTaskSchedulerBuilder()
- 
ThreadPoolTaskSchedulerBuilder@Deprecated(since="3.5.0", forRemoval=true) public ThreadPoolTaskSchedulerBuilder(Integer poolSize, Boolean awaitTermination, Duration awaitTerminationPeriod, String threadNamePrefix, Set<ThreadPoolTaskSchedulerCustomizer> taskSchedulerCustomizers) Deprecated, for removal: This API element is subject to removal in a future version.since 3.5.0 for removal in 4.0.0 in favor of the default constructorConstructs a newThreadPoolTaskSchedulerBuilderinstance with the specified configuration.- Parameters:
- poolSize- the maximum allowed number of threads
- awaitTermination- whether the executor should wait for scheduled tasks to complete on shutdown
- awaitTerminationPeriod- the maximum time the executor is supposed to block on shutdown
- threadNamePrefix- the prefix to use for the names of newly created threads
- taskSchedulerCustomizers- the customizers to apply to the- ThreadPoolTaskScheduler
 
 
- 
- 
Method Details- 
poolSizeSet the maximum allowed number of threads.- Parameters:
- poolSize- the pool size to set
- Returns:
- a new builder instance
 
- 
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 ThreadPoolTaskSchedulerBuilder taskDecorator(org.springframework.core.task.TaskDecorator taskDecorator) Set theTaskDecoratorto be applied to theThreadPoolTaskScheduler.- Parameters:
- taskDecorator- the task decorator to set
- Returns:
- a new builder instance
- Since:
- 3.5.0
 
- 
customizersSet thethreadPoolTaskSchedulerCustomizersthat should be applied to theThreadPoolTaskScheduler. 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 ThreadPoolTaskSchedulerBuilder customizers(Iterable<? extends ThreadPoolTaskSchedulerCustomizer> customizers) Set thethreadPoolTaskSchedulerCustomizersthat should be applied to theThreadPoolTaskScheduler. 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 ThreadPoolTaskSchedulerBuilder additionalCustomizers(ThreadPoolTaskSchedulerCustomizer... customizers) AddthreadPoolTaskSchedulerCustomizersthat should be applied to theThreadPoolTaskScheduler. 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 ThreadPoolTaskSchedulerBuilder additionalCustomizers(Iterable<? extends ThreadPoolTaskSchedulerCustomizer> customizers) AddthreadPoolTaskSchedulerCustomizersthat should be applied to theThreadPoolTaskScheduler. 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.ThreadPoolTaskScheduler build()Build a newThreadPoolTaskSchedulerinstance and configure it using this builder.- Returns:
- a configured ThreadPoolTaskSchedulerinstance.
- See Also:
 
- 
configurepublic <T extends org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler> T configure(T taskScheduler) Configure the providedThreadPoolTaskSchedulerinstance using this builder.- Type Parameters:
- T- the type of task scheduler
- Parameters:
- taskScheduler- the- ThreadPoolTaskSchedulerto configure
- Returns:
- the task scheduler instance
- See Also:
 
 
-