public class TaskExecutorBuilder extends Object
TaskExecutor
. Provides
convenience methods to set common ThreadPoolTaskExecutor
settings and register
taskDecorator(TaskDecorator)
). For advanced configuration, consider using
TaskExecutorCustomizer
.
In a typical auto-configured Spring Boot application this builder is available as a
bean and can be injected whenever a TaskExecutor
is needed.
Constructor and Description |
---|
TaskExecutorBuilder() |
Modifier and Type | Method and Description |
---|---|
TaskExecutorBuilder |
additionalCustomizers(Iterable<TaskExecutorCustomizer> customizers)
Add
TaskExecutorCustomizers that should be applied
to the ThreadPoolTaskExecutor . |
TaskExecutorBuilder |
additionalCustomizers(TaskExecutorCustomizer... customizers)
Add
TaskExecutorCustomizers that should be applied
to the ThreadPoolTaskExecutor . |
TaskExecutorBuilder |
allowCoreThreadTimeOut(boolean allowCoreThreadTimeOut)
Set whether core threads are allow to time out.
|
TaskExecutorBuilder |
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.
|
TaskExecutorBuilder |
awaitTerminationPeriod(Duration awaitTerminationPeriod)
Set the maximum time the executor is supposed to block on shutdown.
|
ThreadPoolTaskExecutor |
build()
Build a new
ThreadPoolTaskExecutor instance and configure it using this
builder. |
<T extends ThreadPoolTaskExecutor> |
build(Class<T> taskExecutorClass)
Build a new
ThreadPoolTaskExecutor instance of the specified type and
configure it using this builder. |
<T extends ThreadPoolTaskExecutor> |
configure(T taskExecutor)
Configure the provided
ThreadPoolTaskExecutor instance using this builder. |
TaskExecutorBuilder |
corePoolSize(int corePoolSize)
Set the core number of threads.
|
TaskExecutorBuilder |
customizers(Iterable<TaskExecutorCustomizer> customizers)
Set the
TaskExecutorCustomizers that should be
applied to the ThreadPoolTaskExecutor . |
TaskExecutorBuilder |
customizers(TaskExecutorCustomizer... customizers)
Set the
TaskExecutorCustomizers that should be
applied to the ThreadPoolTaskExecutor . |
TaskExecutorBuilder |
keepAlive(Duration keepAlive)
Set the time limit for which threads may remain idle before being terminated.
|
TaskExecutorBuilder |
maxPoolSize(int maxPoolSize)
Set the maximum allowed number of threads.
|
TaskExecutorBuilder |
queueCapacity(int queueCapacity)
Set the capacity of the queue.
|
TaskExecutorBuilder |
taskDecorator(TaskDecorator taskDecorator)
Set the
TaskDecorator to use or null to not use any. |
TaskExecutorBuilder |
threadNamePrefix(String threadNamePrefix)
Set the prefix to use for the names of newly created threads.
|
public TaskExecutorBuilder queueCapacity(int queueCapacity)
maxPoolSize
.queueCapacity
- the queue capacity to setpublic TaskExecutorBuilder corePoolSize(int corePoolSize)
Core threads can grow and shrink if allowCoreThreadTimeOut(boolean)
is
enabled.
corePoolSize
- the core pool size to setpublic TaskExecutorBuilder maxPoolSize(int maxPoolSize)
queue
is full, the pool can expand up to that size to accommodate the load.
If the queue capacity
is unbounded, this setting is
ignored.
maxPoolSize
- the max pool size to setpublic TaskExecutorBuilder allowCoreThreadTimeOut(boolean allowCoreThreadTimeOut)
allowCoreThreadTimeOut
- if core threads are allowed to time outpublic TaskExecutorBuilder keepAlive(Duration keepAlive)
keepAlive
- the keep alive to setpublic TaskExecutorBuilder awaitTermination(boolean awaitTermination)
awaitTermination
- whether the executor needs to wait for the tasks to
complete on shutdownawaitTerminationPeriod(Duration)
public TaskExecutorBuilder awaitTerminationPeriod(Duration awaitTerminationPeriod)
awaitTerminationPeriod
- the await termination period to setpublic TaskExecutorBuilder threadNamePrefix(String threadNamePrefix)
threadNamePrefix
- the thread name prefix to setpublic TaskExecutorBuilder taskDecorator(TaskDecorator taskDecorator)
TaskDecorator
to use or null
to not use any.taskDecorator
- the task decorator to usepublic TaskExecutorBuilder customizers(TaskExecutorCustomizer... customizers)
TaskExecutorCustomizers
that should be
applied to the ThreadPoolTaskExecutor
. 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(TaskExecutorCustomizer...)
public TaskExecutorBuilder customizers(Iterable<TaskExecutorCustomizer> customizers)
TaskExecutorCustomizers
that should be
applied to the ThreadPoolTaskExecutor
. 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(TaskExecutorCustomizer...)
public TaskExecutorBuilder additionalCustomizers(TaskExecutorCustomizer... customizers)
TaskExecutorCustomizers
that should be applied
to the ThreadPoolTaskExecutor
. Customizers are applied in the order that
they were added after builder configuration has been applied.customizers
- the customizers to addcustomizers(TaskExecutorCustomizer...)
public TaskExecutorBuilder additionalCustomizers(Iterable<TaskExecutorCustomizer> customizers)
TaskExecutorCustomizers
that should be applied
to the ThreadPoolTaskExecutor
. Customizers are applied in the order that
they were added after builder configuration has been applied.customizers
- the customizers to addcustomizers(TaskExecutorCustomizer...)
public ThreadPoolTaskExecutor build()
ThreadPoolTaskExecutor
instance and configure it using this
builder.ThreadPoolTaskExecutor
instance.build(Class)
,
configure(ThreadPoolTaskExecutor)
public <T extends ThreadPoolTaskExecutor> T build(Class<T> taskExecutorClass)
ThreadPoolTaskExecutor
instance of the specified type and
configure it using this builder.T
- the type of task executortaskExecutorClass
- the template type to createThreadPoolTaskExecutor
instance.build()
,
configure(ThreadPoolTaskExecutor)
public <T extends ThreadPoolTaskExecutor> T configure(T taskExecutor)
ThreadPoolTaskExecutor
instance using this builder.T
- the type of task executortaskExecutor
- the ThreadPoolTaskExecutor
to configurebuild()
,
build(Class)
Copyright © 2020 Pivotal Software, Inc.. All rights reserved.