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 Summary
ConstructorDescriptionThreadPoolTaskSchedulerBuilder
(Integer poolSize, Boolean awaitTermination, Duration awaitTerminationPeriod, String threadNamePrefix, Set<ThreadPoolTaskSchedulerCustomizer> taskSchedulerCustomizers) -
Method Summary
Modifier and TypeMethodDescriptionadditionalCustomizers
(Iterable<? extends ThreadPoolTaskSchedulerCustomizer> customizers) AddthreadPoolTaskSchedulerCustomizers
that should be applied to theThreadPoolTaskScheduler
.additionalCustomizers
(ThreadPoolTaskSchedulerCustomizer... customizers) AddthreadPoolTaskSchedulerCustomizers
that 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.ThreadPoolTaskScheduler
build()
Build a newThreadPoolTaskScheduler
instance and configure it using this builder.<T extends org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler>
Tconfigure
(T taskScheduler) Configure the providedThreadPoolTaskScheduler
instance using this builder.customizers
(Iterable<? extends ThreadPoolTaskSchedulerCustomizer> customizers) Set thethreadPoolTaskSchedulerCustomizers
that should be applied to theThreadPoolTaskScheduler
.customizers
(ThreadPoolTaskSchedulerCustomizer... customizers) Set thethreadPoolTaskSchedulerCustomizers
that should be applied to theThreadPoolTaskScheduler
.poolSize
(int poolSize) Set the maximum allowed number of threads.threadNamePrefix
(String threadNamePrefix) Set the prefix to use for the names of newly created threads.
-
Constructor Details
-
ThreadPoolTaskSchedulerBuilder
public ThreadPoolTaskSchedulerBuilder() -
ThreadPoolTaskSchedulerBuilder
-
-
Method Details
-
poolSize
Set the maximum allowed number of threads.- Parameters:
poolSize
- the pool size to set- Returns:
- a new builder instance
-
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.- Parameters:
awaitTermination
- whether the executor needs to wait for the tasks to complete on shutdown- Returns:
- a new builder instance
- See Also:
-
awaitTerminationPeriod
Set 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
-
threadNamePrefix
Set the prefix to use for the names of newly created threads.- Parameters:
threadNamePrefix
- the thread name prefix to set- Returns:
- a new builder instance
-
customizers
Set thethreadPoolTaskSchedulerCustomizers
that 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:
-
customizers
public ThreadPoolTaskSchedulerBuilder customizers(Iterable<? extends ThreadPoolTaskSchedulerCustomizer> customizers) Set thethreadPoolTaskSchedulerCustomizers
that 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:
-
additionalCustomizers
public ThreadPoolTaskSchedulerBuilder additionalCustomizers(ThreadPoolTaskSchedulerCustomizer... customizers) AddthreadPoolTaskSchedulerCustomizers
that 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:
-
additionalCustomizers
public ThreadPoolTaskSchedulerBuilder additionalCustomizers(Iterable<? extends ThreadPoolTaskSchedulerCustomizer> customizers) AddthreadPoolTaskSchedulerCustomizers
that 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:
-
build
public org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler build()Build a newThreadPoolTaskScheduler
instance and configure it using this builder.- Returns:
- a configured
ThreadPoolTaskScheduler
instance. - See Also:
-
configure
public <T extends org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler> T configure(T taskScheduler) Configure the providedThreadPoolTaskScheduler
instance using this builder.- Type Parameters:
T
- the type of task scheduler- Parameters:
taskScheduler
- theThreadPoolTaskScheduler
to configure- Returns:
- the task scheduler instance
- See Also:
-