public class TaskSchedulerBuilder
extends java.lang.Object
TaskScheduler. Provides
convenience methods to set common ThreadPoolTaskScheduler settings. For
advanced configuration, consider using TaskSchedulerCustomizer.
In a typical auto-configured Spring Boot application this builder is available as a
bean and can be injected whenever a TaskScheduler is needed.
| Constructor and Description |
|---|
TaskSchedulerBuilder() |
TaskSchedulerBuilder(java.lang.Integer poolSize,
java.lang.Boolean awaitTermination,
java.time.Duration awaitTerminationPeriod,
java.lang.String threadNamePrefix,
java.util.Set<TaskSchedulerCustomizer> taskSchedulerCustomizers) |
| Modifier and Type | Method and Description |
|---|---|
TaskSchedulerBuilder |
additionalCustomizers(java.lang.Iterable<TaskSchedulerCustomizer> customizers)
Add
taskSchedulerCustomizers that should be applied
to the ThreadPoolTaskScheduler. |
TaskSchedulerBuilder |
additionalCustomizers(TaskSchedulerCustomizer... customizers)
Add
taskSchedulerCustomizers that should be applied
to the ThreadPoolTaskScheduler. |
TaskSchedulerBuilder |
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.
|
TaskSchedulerBuilder |
awaitTerminationPeriod(java.time.Duration awaitTerminationPeriod)
Set the maximum time the executor is supposed to block on shutdown.
|
org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler |
build()
Build a new
ThreadPoolTaskScheduler instance and configure it using this
builder. |
<T extends org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler> |
configure(T taskScheduler)
Configure the provided
ThreadPoolTaskScheduler instance using this builder. |
TaskSchedulerBuilder |
customizers(java.lang.Iterable<TaskSchedulerCustomizer> customizers)
Set the
taskSchedulerCustomizers that should be
applied to the ThreadPoolTaskScheduler. |
TaskSchedulerBuilder |
customizers(TaskSchedulerCustomizer... customizers)
Set the
TaskSchedulerCustomizers that should be
applied to the ThreadPoolTaskScheduler. |
TaskSchedulerBuilder |
poolSize(int poolSize)
Set the maximum allowed number of threads.
|
TaskSchedulerBuilder |
threadNamePrefix(java.lang.String threadNamePrefix)
Set the prefix to use for the names of newly created threads.
|
public TaskSchedulerBuilder()
public TaskSchedulerBuilder(java.lang.Integer poolSize,
java.lang.Boolean awaitTermination,
java.time.Duration awaitTerminationPeriod,
java.lang.String threadNamePrefix,
java.util.Set<TaskSchedulerCustomizer> taskSchedulerCustomizers)
public TaskSchedulerBuilder poolSize(int poolSize)
poolSize - the pool size to setpublic TaskSchedulerBuilder awaitTermination(boolean awaitTermination)
awaitTermination - whether the executor needs to wait for the tasks to
complete on shutdownawaitTerminationPeriod(Duration)public TaskSchedulerBuilder awaitTerminationPeriod(java.time.Duration awaitTerminationPeriod)
awaitTerminationPeriod - the await termination period to setpublic TaskSchedulerBuilder threadNamePrefix(java.lang.String threadNamePrefix)
threadNamePrefix - the thread name prefix to setpublic TaskSchedulerBuilder customizers(TaskSchedulerCustomizer... customizers)
TaskSchedulerCustomizers that should be
applied to the ThreadPoolTaskScheduler. 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.customizers - the customizers to setadditionalCustomizers(TaskSchedulerCustomizer...)public TaskSchedulerBuilder customizers(java.lang.Iterable<TaskSchedulerCustomizer> customizers)
taskSchedulerCustomizers that should be
applied to the ThreadPoolTaskScheduler. 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.customizers - the customizers to setadditionalCustomizers(TaskSchedulerCustomizer...)public TaskSchedulerBuilder additionalCustomizers(TaskSchedulerCustomizer... customizers)
taskSchedulerCustomizers that should be applied
to the ThreadPoolTaskScheduler. Customizers are applied in the order that
they were added after builder configuration has been applied.customizers - the customizers to addcustomizers(TaskSchedulerCustomizer...)public TaskSchedulerBuilder additionalCustomizers(java.lang.Iterable<TaskSchedulerCustomizer> customizers)
taskSchedulerCustomizers that should be applied
to the ThreadPoolTaskScheduler. Customizers are applied in the order that
they were added after builder configuration has been applied.customizers - the customizers to addcustomizers(TaskSchedulerCustomizer...)public org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler build()
ThreadPoolTaskScheduler instance and configure it using this
builder.ThreadPoolTaskScheduler instance.configure(ThreadPoolTaskScheduler)public <T extends org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler> T configure(T taskScheduler)
ThreadPoolTaskScheduler instance using this builder.T - the type of task schedulertaskScheduler - the ThreadPoolTaskScheduler to configurebuild()