类 TaskExecutorBuilder

java.lang.Object
cn.taketoday.scheduling.support.TaskExecutorBuilder

public class TaskExecutorBuilder extends Object
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.

从以下版本开始:
4.0
作者:
Stephane Nicoll, Filip Hrisafov, Harry Yang
  • 构造器详细资料

    • TaskExecutorBuilder

      public TaskExecutorBuilder()
  • 方法详细资料

    • queueCapacity

      public TaskExecutorBuilder queueCapacity(int queueCapacity)
      Set the capacity of the queue. An unbounded capacity does not increase the pool and therefore ignores maxPoolSize.
      参数:
      queueCapacity - the queue capacity to set
      返回:
      a new builder instance
    • corePoolSize

      public TaskExecutorBuilder corePoolSize(int corePoolSize)
      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.

      参数:
      corePoolSize - the core pool size to set
      返回:
      a new builder instance
    • maxPoolSize

      public TaskExecutorBuilder maxPoolSize(int maxPoolSize)
      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.

      参数:
      maxPoolSize - the max pool size to set
      返回:
      a new builder instance
    • allowCoreThreadTimeOut

      public TaskExecutorBuilder allowCoreThreadTimeOut(boolean allowCoreThreadTimeOut)
      Set whether core threads are allowed to time out. When enabled, this enables dynamic growing and shrinking of the pool.
      参数:
      allowCoreThreadTimeOut - if core threads are allowed to time out
      返回:
      a new builder instance
    • keepAlive

      public TaskExecutorBuilder keepAlive(@Nullable Duration keepAlive)
      Set the time limit for which threads may remain idle before being terminated.
      参数:
      keepAlive - the keep alive to set
      返回:
      a new builder instance
    • awaitTermination

      public 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.
      参数:
      awaitTermination - whether the executor needs to wait for the tasks to complete on shutdown
      返回:
      a new builder instance
      另请参阅:
    • awaitTerminationPeriod

      public TaskExecutorBuilder awaitTerminationPeriod(Duration awaitTerminationPeriod)
      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.
      参数:
      awaitTerminationPeriod - the await termination period to set
      返回:
      a new builder instance
    • threadNamePrefix

      public TaskExecutorBuilder threadNamePrefix(@Nullable String threadNamePrefix)
      Set the prefix to use for the names of newly created threads.
      参数:
      threadNamePrefix - the thread name prefix to set
      返回:
      a new builder instance
    • taskDecorator

      public TaskExecutorBuilder taskDecorator(@Nullable cn.taketoday.core.task.TaskDecorator taskDecorator)
      Set the TaskDecorator to use or null to not use any.
      参数:
      taskDecorator - the task decorator to use
      返回:
      a new builder instance
    • customizers

      public TaskExecutorBuilder customizers(TaskExecutorCustomizer... customizers)
      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.
      参数:
      customizers - the customizers to set
      返回:
      a new builder instance
      另请参阅:
    • customizers

      public TaskExecutorBuilder customizers(Iterable<TaskExecutorCustomizer> customizers)
      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.
      参数:
      customizers - the customizers to set
      返回:
      a new builder instance
      另请参阅:
    • additionalCustomizers

      public TaskExecutorBuilder additionalCustomizers(TaskExecutorCustomizer... customizers)
      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.
      参数:
      customizers - the customizers to add
      返回:
      a new builder instance
      另请参阅:
    • additionalCustomizers

      public TaskExecutorBuilder additionalCustomizers(Iterable<TaskExecutorCustomizer> customizers)
      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.
      参数:
      customizers - the customizers to add
      返回:
      a new builder instance
      另请参阅:
    • build

      public ThreadPoolTaskExecutor build()
      Build a new ThreadPoolTaskExecutor instance and configure it using this builder.
      返回:
      a configured ThreadPoolTaskExecutor instance.
      另请参阅:
    • build

      public <T extends ThreadPoolTaskExecutor> T build(Class<T> taskExecutorClass)
      Build a new ThreadPoolTaskExecutor instance of the specified type and configure it using this builder.
      类型参数:
      T - the type of task executor
      参数:
      taskExecutorClass - the template type to create
      返回:
      a configured ThreadPoolTaskExecutor instance.
      另请参阅:
    • configure

      public <T extends ThreadPoolTaskExecutor> T configure(T taskExecutor)
      Configure the provided ThreadPoolTaskExecutor instance using this builder.
      类型参数:
      T - the type of task executor
      参数:
      taskExecutor - the ThreadPoolTaskExecutor to configure
      返回:
      the task executor instance
      另请参阅: