org.springframework.scheduling.concurrent

## 类 ThreadPoolTaskScheduler

- java.lang.Object
- - org.springframework.util.CustomizableThreadCreator
  - - org.springframework.scheduling.concurrent.CustomizableThreadFactory
    - - org.springframework.scheduling.concurrent.ExecutorConfigurationSupport
      - - org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler

- 所有已实现的接口:
    Serializable, Executor, ThreadFactory, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.core.task.AsyncListenableTaskExecutor, org.springframework.core.task.AsyncTaskExecutor, org.springframework.core.task.TaskExecutor, SchedulingTaskExecutor, TaskScheduler

      public class ThreadPoolTaskScheduler
      extends ExecutorConfigurationSupport
      implements org.springframework.core.task.AsyncListenableTaskExecutor, SchedulingTaskExecutor, TaskScheduler

  Implementation of Spring's `TaskScheduler` interface, wrapping a native `ScheduledThreadPoolExecutor`.
  从以下版本开始:
    3.0
  作者:
    Juergen Hoeller, Mark Fisher
  另请参阅:
    `setPoolSize(int)`, `setRemoveOnCancelPolicy(boolean)`, `ExecutorConfigurationSupport.setThreadFactory(java.util.concurrent.ThreadFactory)`, `setErrorHandler(org.springframework.util.ErrorHandler)`, 序列化表格

- - ### 字段概要

    - ### 从类继承的字段 org.springframework.scheduling.concurrent.ExecutorConfigurationSupport

      `logger`

    - ### 从接口继承的字段 org.springframework.core.task.AsyncTaskExecutor

      `TIMEOUT_IMMEDIATE, TIMEOUT_INDEFINITE`

  - ### 构造器概要

    构造器
    构造器和说明
    `ThreadPoolTaskScheduler()`

  - ### 方法概要

    所有方法 实例方法 具体方法
    限定符和类型 | 方法和说明
    --- | ---
    `protected void` | `cancelRemainingTask(Runnable task)` Cancel the given remaining task which never commended execution, as returned from `ExecutorService.shutdownNow()`.
    `protected ScheduledExecutorService` | `createExecutor(int poolSize, ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler)` Create a new `ScheduledExecutorService` instance.
    `void` | `execute(Runnable task)`
    `void` | `execute(Runnable task, long startTimeout)`
    `int` | `getActiveCount()` Return the number of currently active threads.
    `int` | `getPoolSize()` Return the current pool size.
    `ScheduledExecutorService` | `getScheduledExecutor()` Return the underlying ScheduledExecutorService for native access.
    `ScheduledThreadPoolExecutor` | `getScheduledThreadPoolExecutor()` Return the underlying ScheduledThreadPoolExecutor, if available.
    `protected ExecutorService` | `initializeExecutor(ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler)` Create the target `ExecutorService` instance.
    `boolean` | `isRemoveOnCancelPolicy()` Return the current setting for the remove-on-cancel mode.
    `boolean` | `prefersShortLivedTasks()` Does this `TaskExecutor` prefer short-lived tasks over long-lived tasks?
    `ScheduledFuture<?>` | `schedule(Runnable task, Date startTime)` Schedule the given `Runnable`, invoking it at the specified execution time.
    `ScheduledFuture<?>` | `schedule(Runnable task, Trigger trigger)` Schedule the given `Runnable`, invoking it whenever the trigger indicates a next execution time.
    `ScheduledFuture<?>` | `scheduleAtFixedRate(Runnable task, Date startTime, long period)` Schedule the given `Runnable`, invoking it at the specified execution time and subsequently with the given period.
    `ScheduledFuture<?>` | `scheduleAtFixedRate(Runnable task, long period)` Schedule the given `Runnable`, starting as soon as possible and invoking it with the given period.
    `ScheduledFuture<?>` | `scheduleWithFixedDelay(Runnable task, Date startTime, long delay)` Schedule the given `Runnable`, invoking it at the specified execution time and subsequently with the given delay between the completion of one execution and the start of the next.
    `ScheduledFuture<?>` | `scheduleWithFixedDelay(Runnable task, long delay)` Schedule the given `Runnable`, starting as soon as possible and invoking it with the given delay between the completion of one execution and the start of the next.
    `void` | `setErrorHandler(org.springframework.util.ErrorHandler errorHandler)` Set a custom `ErrorHandler` strategy.
    `void` | `setPoolSize(int poolSize)` Set the ScheduledExecutorService's pool size.
    `void` | `setRemoveOnCancelPolicy(boolean removeOnCancelPolicy)` Set the remove-on-cancel mode on `ScheduledThreadPoolExecutor`.
    `<T> Future<T>` | `submit(Callable<T> task)`
    `Future<?>` | `submit(Runnable task)`
    `<T> org.springframework.util.concurrent.ListenableFuture<T>` | `submitListenable(Callable<T> task)`
    `org.springframework.util.concurrent.ListenableFuture<?>` | `submitListenable(Runnable task)`

    - ### 从类继承的方法 org.springframework.scheduling.concurrent.ExecutorConfigurationSupport

      `afterPropertiesSet, destroy, initialize, setAwaitTerminationSeconds, setBeanName, setRejectedExecutionHandler, setThreadFactory, setThreadNamePrefix, setWaitForTasksToCompleteOnShutdown, shutdown`

    - ### 从类继承的方法 org.springframework.scheduling.concurrent.CustomizableThreadFactory

      `newThread`

    - ### 从类继承的方法 org.springframework.util.CustomizableThreadCreator

      `createThread, getDefaultThreadNamePrefix, getThreadGroup, getThreadNamePrefix, getThreadPriority, isDaemon, nextThreadName, setDaemon, setThreadGroup, setThreadGroupName, setThreadPriority`

    - ### 从类继承的方法 java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### 从接口继承的方法 org.springframework.scheduling.TaskScheduler

      `schedule, scheduleAtFixedRate, scheduleAtFixedRate, scheduleWithFixedDelay, scheduleWithFixedDelay`

- - ### 构造器详细资料

    - #### ThreadPoolTaskScheduler

          public ThreadPoolTaskScheduler()

  - ### 方法详细资料

    - #### setPoolSize

          public void setPoolSize(int poolSize)

      Set the ScheduledExecutorService's pool size. Default is 1.

      This setting can be modified at runtime, for example through JMX.

    - #### setRemoveOnCancelPolicy

          public void setRemoveOnCancelPolicy(boolean removeOnCancelPolicy)

      Set the remove-on-cancel mode on `ScheduledThreadPoolExecutor`.

      Default is `false`. If set to `true`, the target executor will be switched into remove-on-cancel mode (if possible, with a soft fallback otherwise).

      This setting can be modified at runtime, for example through JMX.

    - #### setErrorHandler

          public void setErrorHandler(org.springframework.util.ErrorHandler errorHandler)

      Set a custom `ErrorHandler` strategy.

    - #### initializeExecutor

          protected ExecutorService initializeExecutor(ThreadFactory threadFactory,
                                                       RejectedExecutionHandler rejectedExecutionHandler)

      从类复制的说明: `ExecutorConfigurationSupport`
      Create the target `ExecutorService` instance. Called by `afterPropertiesSet`.
      指定者:
        `initializeExecutor` 在类中 `ExecutorConfigurationSupport`
      参数:
        `threadFactory` - the ThreadFactory to use
        `rejectedExecutionHandler` - the RejectedExecutionHandler to use
      返回:
        a new ExecutorService instance
      另请参阅:
        `ExecutorConfigurationSupport.afterPropertiesSet()`

    - #### createExecutor

          protected ScheduledExecutorService createExecutor(int poolSize,
                                                            ThreadFactory threadFactory,
                                                            RejectedExecutionHandler rejectedExecutionHandler)

      Create a new `ScheduledExecutorService` instance.

      The default implementation creates a `ScheduledThreadPoolExecutor`. Can be overridden in subclasses to provide custom `ScheduledExecutorService` instances.

      参数:
        `poolSize` - the specified pool size
        `threadFactory` - the ThreadFactory to use
        `rejectedExecutionHandler` - the RejectedExecutionHandler to use
      返回:
        a new ScheduledExecutorService instance
      另请参阅:
        `ExecutorConfigurationSupport.afterPropertiesSet()`, `ScheduledThreadPoolExecutor`

    - #### getScheduledExecutor

          public ScheduledExecutorService getScheduledExecutor()
                                                        throws IllegalStateException

      Return the underlying ScheduledExecutorService for native access.
      返回:
        the underlying ScheduledExecutorService (never `null`)
      抛出:
        `IllegalStateException` - if the ThreadPoolTaskScheduler hasn't been initialized yet

    - #### getScheduledThreadPoolExecutor

          public ScheduledThreadPoolExecutor getScheduledThreadPoolExecutor()
                                                                     throws IllegalStateException

      Return the underlying ScheduledThreadPoolExecutor, if available.
      返回:
        the underlying ScheduledExecutorService (never `null`)
      抛出:
        `IllegalStateException` - if the ThreadPoolTaskScheduler hasn't been initialized yet or if the underlying ScheduledExecutorService isn't a ScheduledThreadPoolExecutor
      另请参阅:
        `getScheduledExecutor()`

    - #### getPoolSize

          public int getPoolSize()

      Return the current pool size.

      Requires an underlying `ScheduledThreadPoolExecutor`.

      另请参阅:
        `getScheduledThreadPoolExecutor()`, `ThreadPoolExecutor.getPoolSize()`

    - #### isRemoveOnCancelPolicy

          public boolean isRemoveOnCancelPolicy()

      Return the current setting for the remove-on-cancel mode.

      Requires an underlying `ScheduledThreadPoolExecutor`.

    - #### getActiveCount

          public int getActiveCount()

      Return the number of currently active threads.

      Requires an underlying `ScheduledThreadPoolExecutor`.

      另请参阅:
        `getScheduledThreadPoolExecutor()`, `ThreadPoolExecutor.getActiveCount()`

    - #### execute

          public void execute(Runnable task)

      指定者:
        `execute` 在接口中 `Executor`
      指定者:
        `execute` 在接口中 `org.springframework.core.task.TaskExecutor`

    - #### execute

          public void execute(Runnable task,
                              long startTimeout)

      指定者:
        `execute` 在接口中 `org.springframework.core.task.AsyncTaskExecutor`

    - #### submit

          public Future<?> submit(Runnable task)

      指定者:
        `submit` 在接口中 `org.springframework.core.task.AsyncTaskExecutor`

    - #### submit

          public <T> Future<T> submit(Callable<T> task)

      指定者:
        `submit` 在接口中 `org.springframework.core.task.AsyncTaskExecutor`

    - #### submitListenable

          public org.springframework.util.concurrent.ListenableFuture<?> submitListenable(Runnable task)

      指定者:
        `submitListenable` 在接口中 `org.springframework.core.task.AsyncListenableTaskExecutor`

    - #### submitListenable

          public <T> org.springframework.util.concurrent.ListenableFuture<T> submitListenable(Callable<T> task)

      指定者:
        `submitListenable` 在接口中 `org.springframework.core.task.AsyncListenableTaskExecutor`

    - #### cancelRemainingTask

          protected void cancelRemainingTask(Runnable task)

      从类复制的说明: `ExecutorConfigurationSupport`
      Cancel the given remaining task which never commended execution, as returned from `ExecutorService.shutdownNow()`.
      覆盖:
        `cancelRemainingTask` 在类中 `ExecutorConfigurationSupport`
      参数:
        `task` - the task to cancel (typically a `RunnableFuture`)
      另请参阅:
        `ExecutorConfigurationSupport.shutdown()`, `Future.cancel(boolean)`

    - #### prefersShortLivedTasks

          public boolean prefersShortLivedTasks()

      从接口复制的说明: `SchedulingTaskExecutor`
      Does this `TaskExecutor` prefer short-lived tasks over long-lived tasks?

      A `SchedulingTaskExecutor` implementation can indicate whether it prefers submitted tasks to perform as little work as they can within a single task execution. For example, submitted tasks might break a repeated loop into individual subtasks which submit a follow-up task afterwards (if feasible).

      This should be considered a hint. Of course `TaskExecutor` clients are free to ignore this flag and hence the `SchedulingTaskExecutor` interface overall. However, thread pools will usually indicated a preference for short-lived tasks, to be able to perform more fine-grained scheduling.

      指定者:
        `prefersShortLivedTasks` 在接口中 `SchedulingTaskExecutor`
      返回:
        `true` if this `TaskExecutor` prefers short-lived tasks

    - #### schedule

          @Nullable
          public ScheduledFuture<?> schedule(Runnable task,
                                                        Trigger trigger)

      从接口复制的说明: `TaskScheduler`
      Schedule the given `Runnable`, invoking it whenever the trigger indicates a next execution time.

      Execution will end once the scheduler shuts down or the returned `ScheduledFuture` gets cancelled.

      指定者:
        `schedule` 在接口中 `TaskScheduler`
      参数:
        `task` - the Runnable to execute whenever the trigger fires
        `trigger` - an implementation of the `Trigger` interface, e.g. a `CronTrigger` object wrapping a cron expression
      返回:
        a `ScheduledFuture` representing pending completion of the task, or `null` if the given Trigger object never fires (i.e. returns `null` from `Trigger.nextExecutionTime(org.springframework.scheduling.TriggerContext)`)
      另请参阅:
        `CronTrigger`

    - #### schedule

          public ScheduledFuture<?> schedule(Runnable task,
                                             Date startTime)

      从接口复制的说明: `TaskScheduler`
      Schedule the given `Runnable`, invoking it at the specified execution time.

      Execution will end once the scheduler shuts down or the returned `ScheduledFuture` gets cancelled.

      指定者:
        `schedule` 在接口中 `TaskScheduler`
      参数:
        `task` - the Runnable to execute whenever the trigger fires
        `startTime` - the desired execution time for the task (if this is in the past, the task will be executed immediately, i.e. as soon as possible)
      返回:
        a `ScheduledFuture` representing pending completion of the task

    - #### scheduleAtFixedRate

          public ScheduledFuture<?> scheduleAtFixedRate(Runnable task,
                                                        Date startTime,
                                                        long period)

      从接口复制的说明: `TaskScheduler`
      Schedule the given `Runnable`, invoking it at the specified execution time and subsequently with the given period.

      Execution will end once the scheduler shuts down or the returned `ScheduledFuture` gets cancelled.

      指定者:
        `scheduleAtFixedRate` 在接口中 `TaskScheduler`
      参数:
        `task` - the Runnable to execute whenever the trigger fires
        `startTime` - the desired first execution time for the task (if this is in the past, the task will be executed immediately, i.e. as soon as possible)
        `period` - the interval between successive executions of the task (in milliseconds)
      返回:
        a `ScheduledFuture` representing pending completion of the task

    - #### scheduleAtFixedRate

          public ScheduledFuture<?> scheduleAtFixedRate(Runnable task,
                                                        long period)

      从接口复制的说明: `TaskScheduler`
      Schedule the given `Runnable`, starting as soon as possible and invoking it with the given period.

      Execution will end once the scheduler shuts down or the returned `ScheduledFuture` gets cancelled.

      指定者:
        `scheduleAtFixedRate` 在接口中 `TaskScheduler`
      参数:
        `task` - the Runnable to execute whenever the trigger fires
        `period` - the interval between successive executions of the task (in milliseconds)
      返回:
        a `ScheduledFuture` representing pending completion of the task

    - #### scheduleWithFixedDelay

          public ScheduledFuture<?> scheduleWithFixedDelay(Runnable task,
                                                           Date startTime,
                                                           long delay)

      从接口复制的说明: `TaskScheduler`
      Schedule the given `Runnable`, invoking it at the specified execution time and subsequently with the given delay between the completion of one execution and the start of the next.

      Execution will end once the scheduler shuts down or the returned `ScheduledFuture` gets cancelled.

      指定者:
        `scheduleWithFixedDelay` 在接口中 `TaskScheduler`
      参数:
        `task` - the Runnable to execute whenever the trigger fires
        `startTime` - the desired first execution time for the task (if this is in the past, the task will be executed immediately, i.e. as soon as possible)
        `delay` - the delay between the completion of one execution and the start of the next (in milliseconds)
      返回:
        a `ScheduledFuture` representing pending completion of the task

    - #### scheduleWithFixedDelay

          public ScheduledFuture<?> scheduleWithFixedDelay(Runnable task,
                                                           long delay)

      从接口复制的说明: `TaskScheduler`
      Schedule the given `Runnable`, starting as soon as possible and invoking it with the given delay between the completion of one execution and the start of the next.

      Execution will end once the scheduler shuts down or the returned `ScheduledFuture` gets cancelled.

      指定者:
        `scheduleWithFixedDelay` 在接口中 `TaskScheduler`
      参数:
        `task` - the Runnable to execute whenever the trigger fires
        `delay` - the delay between the completion of one execution and the start of the next (in milliseconds)
      返回:
        a `ScheduledFuture` representing pending completion of the task