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(Integer queueCapacity,
Integer corePoolSize,
Integer maxPoolSize,
Boolean allowCoreThreadTimeOut,
Duration keepAlive,
String threadNamePrefix,
TaskDecorator taskDecorator,
Set<TaskExecutorCustomizer> taskExecutorCustomizers) |
TaskExecutorBuilder(TaskExecutorCustomizer... taskExecutorCustomizers) |
Modifier and Type | Method and Description |
---|---|
TaskExecutorBuilder |
additionalCustomizers(Collection<? extends TaskExecutorCustomizer> taskExecutorCustomizers)
Add
TaskExecutorCustomizers that should be applied
to the ThreadPoolTaskExecutor . |
TaskExecutorBuilder |
additionalCustomizers(TaskExecutorCustomizer... taskExecutorCustomizers)
Add
TaskExecutorCustomizers that should be applied
to the ThreadPoolTaskExecutor . |
TaskExecutorBuilder |
allowCoreThreadTimeOut(boolean allowCoreThreadTimeOut)
Set whether core threads are allow to time out.
|
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(Collection<? extends TaskExecutorCustomizer> taskExecutorCustomizers)
Set the
TaskExecutorCustomizers that should be
applied to the ThreadPoolTaskExecutor . |
TaskExecutorBuilder |
customizers(TaskExecutorCustomizer... taskExecutorCustomizers)
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(TaskExecutorCustomizer... taskExecutorCustomizers)
public TaskExecutorBuilder(Integer queueCapacity, Integer corePoolSize, Integer maxPoolSize, Boolean allowCoreThreadTimeOut, Duration keepAlive, String threadNamePrefix, TaskDecorator taskDecorator, Set<TaskExecutorCustomizer> taskExecutorCustomizers)
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 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... taskExecutorCustomizers)
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.taskExecutorCustomizers
- the customizers to setadditionalCustomizers(TaskExecutorCustomizer...)
public TaskExecutorBuilder customizers(Collection<? extends TaskExecutorCustomizer> taskExecutorCustomizers)
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.taskExecutorCustomizers
- the customizers to setadditionalCustomizers(TaskExecutorCustomizer...)
public TaskExecutorBuilder additionalCustomizers(TaskExecutorCustomizer... taskExecutorCustomizers)
TaskExecutorCustomizers
that should be applied
to the ThreadPoolTaskExecutor
. Customizers are applied in the order that
they were added after builder configuration has been applied.taskExecutorCustomizers
- the customizers to addcustomizers(TaskExecutorCustomizer...)
public TaskExecutorBuilder additionalCustomizers(Collection<? extends TaskExecutorCustomizer> taskExecutorCustomizers)
TaskExecutorCustomizers
that should be applied
to the ThreadPoolTaskExecutor
. Customizers are applied in the order that
they were added after builder configuration has been applied.taskExecutorCustomizers
- 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 © 2018 Pivotal Software, Inc.. All rights reserved.