org.springframework.core.task

## 类 SimpleAsyncTaskExecutor

- java.lang.Object
- - org.springframework.util.CustomizableThreadCreator
  - - org.springframework.core.task.SimpleAsyncTaskExecutor

- 所有已实现的接口:
    Serializable, Executor, AsyncListenableTaskExecutor, AsyncTaskExecutor, TaskExecutor

      public class SimpleAsyncTaskExecutor
      extends CustomizableThreadCreator
      implements AsyncListenableTaskExecutor, Serializable

  `TaskExecutor` implementation that fires up a new Thread for each task, executing it asynchronously.

  Supports limiting concurrent threads through the "concurrencyLimit" bean property. By default, the number of concurrent threads is unlimited.

  NOTE: This implementation does not reuse threads! Consider a thread-pooling TaskExecutor implementation instead, in particular for executing a large number of short-lived tasks.

  从以下版本开始:
    2.0
  作者:
    Juergen Hoeller
  另请参阅:
    `setConcurrencyLimit(int)`, `SyncTaskExecutor`, `org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor`, `org.springframework.scheduling.commonj.WorkManagerTaskExecutor`, 序列化表格

- - ### 字段概要

    字段
    限定符和类型 | 字段和说明
    --- | ---
    `static int` | `NO_CONCURRENCY` Switch concurrency 'off': that is, don't allow any concurrent invocations.
    `static int` | `UNBOUNDED_CONCURRENCY` Permit any number of concurrent invocations: that is, don't throttle concurrency.

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

      `TIMEOUT_IMMEDIATE, TIMEOUT_INDEFINITE`

  - ### 构造器概要

    构造器
    构造器和说明
    `SimpleAsyncTaskExecutor()` Create a new SimpleAsyncTaskExecutor with default thread name prefix.
    `SimpleAsyncTaskExecutor(String threadNamePrefix)` Create a new SimpleAsyncTaskExecutor with the given thread name prefix.
    `SimpleAsyncTaskExecutor(ThreadFactory threadFactory)` Create a new SimpleAsyncTaskExecutor with the given external thread factory.

  - ### 方法概要

    所有方法 实例方法 具体方法
    限定符和类型 | 方法和说明
    --- | ---
    `protected void` | `doExecute(Runnable task)` Template method for the actual execution of a task.
    `void` | `execute(Runnable task)` Executes the given task, within a concurrency throttle if configured (through the superclass's settings).
    `void` | `execute(Runnable task, long startTimeout)` Executes the given task, within a concurrency throttle if configured (through the superclass's settings).
    `int` | `getConcurrencyLimit()` Return the maximum number of parallel accesses allowed.
    `ThreadFactory` | `getThreadFactory()` Return the external factory to use for creating new Threads, if any.
    `boolean` | `isThrottleActive()` Return whether this throttle is currently active.
    `void` | `setConcurrencyLimit(int concurrencyLimit)` Set the maximum number of parallel accesses allowed
    `void` | `setTaskDecorator(TaskDecorator taskDecorator)` Specify a custom `TaskDecorator` to be applied to any `Runnable` about to be executed.
    `void` | `setThreadFactory(ThreadFactory threadFactory)` Specify an external factory to use for creating new Threads, instead of relying on the local properties of this executor.
    `<T> Future<T>` | `submit(Callable<T> task)` Submit a Callable task for execution, receiving a Future representing that task.
    `Future<?>` | `submit(Runnable task)` Submit a Runnable task for execution, receiving a Future representing that task.
    `<T> ListenableFuture<T>` | `submitListenable(Callable<T> task)` Submit a `Callable` task for execution, receiving a `ListenableFuture` representing that task.
    `ListenableFuture<?>` | `submitListenable(Runnable task)` Submit a `Runnable` task for execution, receiving a `ListenableFuture` representing that task.

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

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

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

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

- - ### 字段详细资料

    - #### UNBOUNDED_CONCURRENCY

          public static final int UNBOUNDED_CONCURRENCY

      Permit any number of concurrent invocations: that is, don't throttle concurrency.
      另请参阅:
        `ConcurrencyThrottleSupport.UNBOUNDED_CONCURRENCY`, 常量字段值

    - #### NO_CONCURRENCY

          public static final int NO_CONCURRENCY

      Switch concurrency 'off': that is, don't allow any concurrent invocations.
      另请参阅:
        `ConcurrencyThrottleSupport.NO_CONCURRENCY`, 常量字段值

  - ### 构造器详细资料

    - #### SimpleAsyncTaskExecutor

          public SimpleAsyncTaskExecutor()

      Create a new SimpleAsyncTaskExecutor with default thread name prefix.

    - #### SimpleAsyncTaskExecutor

          public SimpleAsyncTaskExecutor(String threadNamePrefix)

      Create a new SimpleAsyncTaskExecutor with the given thread name prefix.
      参数:
        `threadNamePrefix` - the prefix to use for the names of newly created threads

    - #### SimpleAsyncTaskExecutor

          public SimpleAsyncTaskExecutor(ThreadFactory threadFactory)

      Create a new SimpleAsyncTaskExecutor with the given external thread factory.
      参数:
        `threadFactory` - the factory to use for creating new Threads

  - ### 方法详细资料

    - #### setThreadFactory

          public void setThreadFactory(@Nullable
                                       ThreadFactory threadFactory)

      Specify an external factory to use for creating new Threads, instead of relying on the local properties of this executor.

      You may specify an inner ThreadFactory bean or also a ThreadFactory reference obtained from JNDI (on a Java EE 6 server) or some other lookup mechanism.

      另请参阅:
        `CustomizableThreadCreator.setThreadNamePrefix(java.lang.String)`, `CustomizableThreadCreator.setThreadPriority(int)`

    - #### getThreadFactory

          @Nullable
          public final ThreadFactory getThreadFactory()

      Return the external factory to use for creating new Threads, if any.

    - #### setTaskDecorator

          public final void setTaskDecorator(TaskDecorator taskDecorator)

      Specify a custom `TaskDecorator` to be applied to any `Runnable` about to be executed.

      Note that such a decorator is not necessarily being applied to the user-supplied `Runnable`/`Callable` but rather to the actual execution callback (which may be a wrapper around the user-supplied task).

      The primary use case is to set some execution context around the task's invocation, or to provide some monitoring/statistics for task execution.

      从以下版本开始:
        4.3

    - #### setConcurrencyLimit

          public void setConcurrencyLimit(int concurrencyLimit)

      Set the maximum number of parallel accesses allowed. -1 indicates no concurrency limit at all.

      In principle, this limit can be changed at runtime, although it is generally designed as a config time setting. NOTE: Do not switch between -1 and any concrete limit at runtime, as this will lead to inconsistent concurrency counts: A limit of -1 effectively turns off concurrency counting completely.

      另请参阅:
        `UNBOUNDED_CONCURRENCY`

    - #### getConcurrencyLimit

          public final int getConcurrencyLimit()

      Return the maximum number of parallel accesses allowed.

    - #### isThrottleActive

          public final boolean isThrottleActive()

      Return whether this throttle is currently active.
      返回:
        `true` if the concurrency limit for this instance is active
      另请参阅:
        `getConcurrencyLimit()`, `setConcurrencyLimit(int)`

    - #### execute

          public void execute(Runnable task)

      Executes the given task, within a concurrency throttle if configured (through the superclass's settings).
      指定者:
        `execute` 在接口中 `Executor`
      指定者:
        `execute` 在接口中 `TaskExecutor`
      参数:
        `task` - the `Runnable` to execute (never `null`)
      另请参阅:
        `doExecute(Runnable)`

    - #### execute

          public void execute(Runnable task,
                              long startTimeout)

      Executes the given task, within a concurrency throttle if configured (through the superclass's settings).

      Executes urgent tasks (with 'immediate' timeout) directly, bypassing the concurrency throttle (if active). All other tasks are subject to throttling.

      指定者:
        `execute` 在接口中 `AsyncTaskExecutor`
      参数:
        `task` - the `Runnable` to execute (never `null`)
        `startTimeout` - the time duration (milliseconds) within which the task is supposed to start. This is intended as a hint to the executor, allowing for preferred handling of immediate tasks. Typical values are `AsyncTaskExecutor.TIMEOUT_IMMEDIATE` or `AsyncTaskExecutor.TIMEOUT_INDEFINITE` (the default as used by `TaskExecutor.execute(Runnable)`).
      另请参阅:
        `AsyncTaskExecutor.TIMEOUT_IMMEDIATE`, `doExecute(Runnable)`

    - #### submit

          public Future<?> submit(Runnable task)

      从接口复制的说明: `AsyncTaskExecutor`
      Submit a Runnable task for execution, receiving a Future representing that task. The Future will return a `null` result upon completion.
      指定者:
        `submit` 在接口中 `AsyncTaskExecutor`
      参数:
        `task` - the `Runnable` to execute (never `null`)
      返回:
        a Future representing pending completion of the task

    - #### submit

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

      从接口复制的说明: `AsyncTaskExecutor`
      Submit a Callable task for execution, receiving a Future representing that task. The Future will return the Callable's result upon completion.
      指定者:
        `submit` 在接口中 `AsyncTaskExecutor`
      参数:
        `task` - the `Callable` to execute (never `null`)
      返回:
        a Future representing pending completion of the task

    - #### submitListenable

          public ListenableFuture<?> submitListenable(Runnable task)

      从接口复制的说明: `AsyncListenableTaskExecutor`
      Submit a `Runnable` task for execution, receiving a `ListenableFuture` representing that task. The Future will return a `null` result upon completion.
      指定者:
        `submitListenable` 在接口中 `AsyncListenableTaskExecutor`
      参数:
        `task` - the `Runnable` to execute (never `null`)
      返回:
        a `ListenableFuture` representing pending completion of the task

    - #### submitListenable

          public <T> ListenableFuture<T> submitListenable(Callable<T> task)

      从接口复制的说明: `AsyncListenableTaskExecutor`
      Submit a `Callable` task for execution, receiving a `ListenableFuture` representing that task. The Future will return the Callable's result upon completion.
      指定者:
        `submitListenable` 在接口中 `AsyncListenableTaskExecutor`
      参数:
        `task` - the `Callable` to execute (never `null`)
      返回:
        a `ListenableFuture` representing pending completion of the task

    - #### doExecute

          protected void doExecute(Runnable task)

      Template method for the actual execution of a task.

      The default implementation creates a new Thread and starts it.

      参数:
        `task` - the Runnable to execute
      另请参阅:
        `setThreadFactory(java.util.concurrent.ThreadFactory)`, `CustomizableThreadCreator.createThread(java.lang.Runnable)`, `Thread.start()`