Package org.springframework.boot.task
Class TaskSchedulerBuilder
- java.lang.Object
- org.springframework.boot.task.TaskSchedulerBuilder
public class TaskSchedulerBuilder extends Object
Builder that can be used to configure and create aTaskScheduler
. Provides convenience methods to set commonThreadPoolTaskScheduler
settings. For advanced configuration, consider usingTaskSchedulerCustomizer
.In a typical auto-configured Spring Boot application this builder is available as a bean and can be injected whenever a
TaskScheduler
is needed.- Since:
- 2.1.0
Constructor Summary
Constructors Constructor Description TaskSchedulerBuilder()
TaskSchedulerBuilder(Integer poolSize, String threadNamePrefix, Set<TaskSchedulerCustomizer> taskSchedulerCustomizers)
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TaskSchedulerBuilder
additionalCustomizers(Iterable<TaskSchedulerCustomizer> customizers)
AddtaskSchedulerCustomizers
that should be applied to theThreadPoolTaskScheduler
.TaskSchedulerBuilder
additionalCustomizers(TaskSchedulerCustomizer... customizers)
AddtaskSchedulerCustomizers
that should be applied to theThreadPoolTaskScheduler
.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.TaskSchedulerBuilder
customizers(Iterable<TaskSchedulerCustomizer> customizers)
Set thetaskSchedulerCustomizers
that should be applied to theThreadPoolTaskScheduler
.TaskSchedulerBuilder
customizers(TaskSchedulerCustomizer... customizers)
Set theTaskSchedulerCustomizers
that should be applied to theThreadPoolTaskScheduler
.TaskSchedulerBuilder
poolSize(int poolSize)
Set the maximum allowed number of threads.TaskSchedulerBuilder
threadNamePrefix(String threadNamePrefix)
Set the prefix to use for the names of newly created threads.
Constructor Detail
TaskSchedulerBuilder
public TaskSchedulerBuilder()
TaskSchedulerBuilder
public TaskSchedulerBuilder(Integer poolSize, String threadNamePrefix, Set<TaskSchedulerCustomizer> taskSchedulerCustomizers)
Method Detail
poolSize
public TaskSchedulerBuilder poolSize(int poolSize)
Set the maximum allowed number of threads.- Parameters:
poolSize
- the pool size to set- Returns:
- a new builder instance
threadNamePrefix
public TaskSchedulerBuilder threadNamePrefix(String 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
public TaskSchedulerBuilder customizers(TaskSchedulerCustomizer... customizers)
Set theTaskSchedulerCustomizers
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(TaskSchedulerCustomizer...)
customizers
public TaskSchedulerBuilder customizers(Iterable<TaskSchedulerCustomizer> customizers)
Set thetaskSchedulerCustomizers
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(TaskSchedulerCustomizer...)
additionalCustomizers
public TaskSchedulerBuilder additionalCustomizers(TaskSchedulerCustomizer... customizers)
AddtaskSchedulerCustomizers
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:
customizers(TaskSchedulerCustomizer...)
additionalCustomizers
public TaskSchedulerBuilder additionalCustomizers(Iterable<TaskSchedulerCustomizer> customizers)
AddtaskSchedulerCustomizers
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:
customizers(TaskSchedulerCustomizer...)
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(ThreadPoolTaskScheduler)
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:
build()