Class TaskExecutorBuilder

java.lang.Object
org.springframework.boot.task.TaskExecutorBuilder

@Deprecated(since="3.2.0", forRemoval=true) public class TaskExecutorBuilder extends Object
Deprecated, for removal: This API element is subject to removal in a future version.
since 3.2.0 for removal in 3.4.0 in favor of ThreadPoolTaskExecutorBuilder
Builder that can be used to configure and create a 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.

Since:
2.1.0
  • Constructor Summary

    Constructors
    Constructor
    Description
    Deprecated, for removal: This API element is subject to removal in a future version.
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Deprecated, for removal: This API element is subject to removal in a future version.
    Add TaskExecutorCustomizers that should be applied to the ThreadPoolTaskExecutor.
    Deprecated, for removal: This API element is subject to removal in a future version.
    Add TaskExecutorCustomizers that should be applied to the ThreadPoolTaskExecutor.
    allowCoreThreadTimeOut(boolean allowCoreThreadTimeOut)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Set whether core threads are allowed to time out.
    awaitTermination(boolean awaitTermination)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Set whether the executor should wait for scheduled tasks to complete on shutdown, not interrupting running tasks and executing all tasks in the queue.
    awaitTerminationPeriod(Duration awaitTerminationPeriod)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Set the maximum time the executor is supposed to block on shutdown.
    org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
    Deprecated, for removal: This API element is subject to removal in a future version.
    Build a new ThreadPoolTaskExecutor instance and configure it using this builder.
    <T extends org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor>
    T
    build(Class<T> taskExecutorClass)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Build a new ThreadPoolTaskExecutor instance of the specified type and configure it using this builder.
    <T extends org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor>
    T
    configure(T taskExecutor)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Configure the provided ThreadPoolTaskExecutor instance using this builder.
    corePoolSize(int corePoolSize)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Set the core number of threads.
    Deprecated, for removal: This API element is subject to removal in a future version.
    Set the TaskExecutorCustomizers that should be applied to the ThreadPoolTaskExecutor.
    Deprecated, for removal: This API element is subject to removal in a future version.
    Set the TaskExecutorCustomizers that should be applied to the ThreadPoolTaskExecutor.
    keepAlive(Duration keepAlive)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Set the time limit for which threads may remain idle before being terminated.
    maxPoolSize(int maxPoolSize)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Set the maximum allowed number of threads.
    queueCapacity(int queueCapacity)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Set the capacity of the queue.
    taskDecorator(org.springframework.core.task.TaskDecorator taskDecorator)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Set the TaskDecorator to use or null to not use any.
    threadNamePrefix(String threadNamePrefix)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Set the prefix to use for the names of newly created threads.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • TaskExecutorBuilder

      public TaskExecutorBuilder()
      Deprecated, for removal: This API element is subject to removal in a future version.
  • Method Details

    • queueCapacity

      public TaskExecutorBuilder queueCapacity(int queueCapacity)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Set the capacity of the queue. An unbounded capacity does not increase the pool and therefore ignores maxPoolSize.
      Parameters:
      queueCapacity - the queue capacity to set
      Returns:
      a new builder instance
    • corePoolSize

      public TaskExecutorBuilder corePoolSize(int corePoolSize)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Set the core number of threads. Effectively that maximum number of threads as long as the queue is not full.

      Core threads can grow and shrink if allowCoreThreadTimeOut(boolean) is enabled.

      Parameters:
      corePoolSize - the core pool size to set
      Returns:
      a new builder instance
    • maxPoolSize

      public TaskExecutorBuilder maxPoolSize(int maxPoolSize)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Set the maximum allowed number of threads. When the 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.

      Parameters:
      maxPoolSize - the max pool size to set
      Returns:
      a new builder instance
    • allowCoreThreadTimeOut

      public TaskExecutorBuilder allowCoreThreadTimeOut(boolean allowCoreThreadTimeOut)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Set whether core threads are allowed to time out. When enabled, this enables dynamic growing and shrinking of the pool.
      Parameters:
      allowCoreThreadTimeOut - if core threads are allowed to time out
      Returns:
      a new builder instance
    • keepAlive

      public TaskExecutorBuilder keepAlive(Duration keepAlive)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Set the time limit for which threads may remain idle before being terminated.
      Parameters:
      keepAlive - the keep alive to set
      Returns:
      a new builder instance
    • awaitTermination

      public TaskExecutorBuilder awaitTermination(boolean awaitTermination)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Set whether the executor should wait for scheduled tasks to complete on shutdown, not interrupting running tasks and executing all tasks in the queue.
      Parameters:
      awaitTermination - whether the executor needs to wait for the tasks to complete on shutdown
      Returns:
      a new builder instance
      See Also:
    • awaitTerminationPeriod

      public TaskExecutorBuilder awaitTerminationPeriod(Duration awaitTerminationPeriod)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Set the maximum time the executor is supposed to block on shutdown. When set, the executor blocks on shutdown in order to wait for remaining tasks to complete their execution before the rest of the container continues to shut down. This is particularly useful if your remaining tasks are likely to need access to other resources that are also managed by the container.
      Parameters:
      awaitTerminationPeriod - the await termination period to set
      Returns:
      a new builder instance
    • threadNamePrefix

      public TaskExecutorBuilder threadNamePrefix(String threadNamePrefix)
      Deprecated, for removal: This API element is subject to removal in a future version.
      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
    • taskDecorator

      public TaskExecutorBuilder taskDecorator(org.springframework.core.task.TaskDecorator taskDecorator)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Set the TaskDecorator to use or null to not use any.
      Parameters:
      taskDecorator - the task decorator to use
      Returns:
      a new builder instance
    • customizers

      public TaskExecutorBuilder customizers(TaskExecutorCustomizer... customizers)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Set the 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.
      Parameters:
      customizers - the customizers to set
      Returns:
      a new builder instance
      See Also:
    • customizers

      public TaskExecutorBuilder customizers(Iterable<TaskExecutorCustomizer> customizers)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Set the 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.
      Parameters:
      customizers - the customizers to set
      Returns:
      a new builder instance
      See Also:
    • additionalCustomizers

      public TaskExecutorBuilder additionalCustomizers(TaskExecutorCustomizer... customizers)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Add TaskExecutorCustomizers that should be applied to the ThreadPoolTaskExecutor. 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 TaskExecutorBuilder additionalCustomizers(Iterable<TaskExecutorCustomizer> customizers)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Add TaskExecutorCustomizers that should be applied to the ThreadPoolTaskExecutor. 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

      public org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor build()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Build a new ThreadPoolTaskExecutor instance and configure it using this builder.
      Returns:
      a configured ThreadPoolTaskExecutor instance.
      See Also:
    • build

      public <T extends org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor> T build(Class<T> taskExecutorClass)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Build a new ThreadPoolTaskExecutor instance 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 ThreadPoolTaskExecutor instance.
      See Also:
    • configure

      public <T extends org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor> T configure(T taskExecutor)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Configure the provided ThreadPoolTaskExecutor instance using this builder.
      Type Parameters:
      T - the type of task executor
      Parameters:
      taskExecutor - the ThreadPoolTaskExecutor to configure
      Returns:
      the task executor instance
      See Also: