Class SimpleAsyncTaskExecutorBuilder
java.lang.Object
org.springframework.boot.task.SimpleAsyncTaskExecutorBuilder
Builder that can be used to configure and create a
SimpleAsyncTaskExecutor.
Provides convenience methods to set common SimpleAsyncTaskExecutor settings and
register taskDecorator(TaskDecorator)). For advanced configuration, consider
using SimpleAsyncTaskExecutorCustomizer.
In a typical auto-configured Spring Boot application this builder is available as a
bean and can be injected whenever a SimpleAsyncTaskExecutor is needed.
- Since:
- 3.2.0
- Author:
- Stephane Nicoll, Filip Hrisafov, Moritz Halbritter, Yanming Zhou
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadditionalCustomizers(Iterable<? extends SimpleAsyncTaskExecutorCustomizer> customizers) Addcustomizersthat should be applied to theSimpleAsyncTaskExecutor.additionalCustomizers(SimpleAsyncTaskExecutorCustomizer... customizers) Addcustomizersthat should be applied to theSimpleAsyncTaskExecutor.build()Build a newSimpleAsyncTaskExecutorinstance and configure it using this builder.<T extends SimpleAsyncTaskExecutor>
TBuild a newSimpleAsyncTaskExecutorinstance of the specified type and configure it using this builder.cancelRemainingTasksOnClose(boolean cancelRemainingTasksOnClose) Set whether to cancel remaining tasks on close.concurrencyLimit(@Nullable Integer concurrencyLimit) Set the concurrency limit.<T extends SimpleAsyncTaskExecutor>
Tconfigure(T taskExecutor) Configure the providedSimpleAsyncTaskExecutorinstance using this builder.customizers(Iterable<? extends SimpleAsyncTaskExecutorCustomizer> customizers) Set thecustomizersthat should be applied to theSimpleAsyncTaskExecutor.customizers(SimpleAsyncTaskExecutorCustomizer... customizers) Set thecustomizersthat should be applied to theSimpleAsyncTaskExecutor.rejectTasksWhenLimitReached(boolean rejectTasksWhenLimitReached) Set whether to reject tasks when the concurrency limit has been reached.taskDecorator(@Nullable TaskDecorator taskDecorator) Set theTaskDecoratorto use ornullto not use any.taskTerminationTimeout(@Nullable Duration taskTerminationTimeout) Set the task termination timeout.threadNamePrefix(@Nullable String threadNamePrefix) Set the prefix to use for the names of newly created threads.virtualThreads(@Nullable Boolean virtualThreads) Set whether to use virtual threads.
-
Constructor Details
-
SimpleAsyncTaskExecutorBuilder
public SimpleAsyncTaskExecutorBuilder()
-
-
Method Details
-
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
-
virtualThreads
Set whether to use virtual threads.- Parameters:
virtualThreads- whether to use virtual threads- Returns:
- a new builder instance
-
cancelRemainingTasksOnClose
public SimpleAsyncTaskExecutorBuilder cancelRemainingTasksOnClose(boolean cancelRemainingTasksOnClose) Set whether to cancel remaining tasks on close. By defaultfalsenot tracking active threads at all or just interrupting any remaining threads that still have not finished after the specifiedtaskTerminationTimeout. Switch this totruefor immediate interruption on close, either in combination with a subsequent termination timeout or without any waiting at all, depending on whether ataskTerminationTimeouthas been specified as well.- Parameters:
cancelRemainingTasksOnClose- whether to cancel remaining tasks on close- Returns:
- a new builder instance
- Since:
- 4.0.0
-
rejectTasksWhenLimitReached
public SimpleAsyncTaskExecutorBuilder rejectTasksWhenLimitReached(boolean rejectTasksWhenLimitReached) Set whether to reject tasks when the concurrency limit has been reached. By defaultfalseto block the caller until the submission can be accepted. Switch totruefor immediate rejection instead.- Parameters:
rejectTasksWhenLimitReached- whether to reject tasks when the concurrency limit has been reached- Returns:
- a new builder instance
- Since:
- 3.5.0
-
concurrencyLimit
Set the concurrency limit.- Parameters:
concurrencyLimit- the concurrency limit- Returns:
- a new builder instance
-
taskDecorator
Set theTaskDecoratorto use ornullto not use any.- Parameters:
taskDecorator- the task decorator to use- Returns:
- a new builder instance
-
taskTerminationTimeout
public SimpleAsyncTaskExecutorBuilder taskTerminationTimeout(@Nullable Duration taskTerminationTimeout) Set the task termination timeout.- Parameters:
taskTerminationTimeout- the task termination timeout- Returns:
- a new builder instance
- Since:
- 3.2.1
-
customizers
Set thecustomizersthat should be applied to theSimpleAsyncTaskExecutor. 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 SimpleAsyncTaskExecutorBuilder customizers(Iterable<? extends SimpleAsyncTaskExecutorCustomizer> customizers) Set thecustomizersthat should be applied to theSimpleAsyncTaskExecutor. 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 SimpleAsyncTaskExecutorBuilder additionalCustomizers(SimpleAsyncTaskExecutorCustomizer... customizers) Addcustomizersthat should be applied to theSimpleAsyncTaskExecutor. 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 SimpleAsyncTaskExecutorBuilder additionalCustomizers(Iterable<? extends SimpleAsyncTaskExecutorCustomizer> customizers) Addcustomizersthat should be applied to theSimpleAsyncTaskExecutor. 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
Build a newSimpleAsyncTaskExecutorinstance and configure it using this builder.- Returns:
- a configured
SimpleAsyncTaskExecutorinstance. - See Also:
-
build
Build a newSimpleAsyncTaskExecutorinstance of the specified type and configure it using this builder.- Type Parameters:
T- the type of task executor- Parameters:
taskExecutorClass- the template type to create- Returns:
- a configured
SimpleAsyncTaskExecutorinstance. - See Also:
-
configure
Configure the providedSimpleAsyncTaskExecutorinstance using this builder.- Type Parameters:
T- the type of task executor- Parameters:
taskExecutor- theSimpleAsyncTaskExecutorto configure- Returns:
- the task executor instance
- See Also:
-