org.springframework.scheduling.concurrent

## 类 ScheduledExecutorTask

- java.lang.Object
- - org.springframework.scheduling.concurrent.ScheduledExecutorTask

-     public class ScheduledExecutorTask
      extends Object

  JavaBean that describes a scheduled executor task, consisting of the `Runnable` and a delay plus period. The period needs to be specified; there is no point in a default for it.

  The `ScheduledExecutorService` does not offer more sophisticated scheduling options such as cron expressions. Consider using `ThreadPoolTaskScheduler` for such needs.

  Note that the `ScheduledExecutorService` mechanism uses a `Runnable` instance that is shared between repeated executions, in contrast to Quartz which creates a new Job instance for each execution.

  从以下版本开始:
    2.0
  作者:
    Juergen Hoeller
  另请参阅:
    `ScheduledExecutorService.scheduleWithFixedDelay(java.lang.Runnable, long, long, java.util.concurrent.TimeUnit)`, `ScheduledExecutorService.scheduleAtFixedRate(java.lang.Runnable, long, long, java.util.concurrent.TimeUnit)`

- - ### 构造器概要

    构造器
    构造器和说明
    `ScheduledExecutorTask()` Create a new ScheduledExecutorTask, to be populated via bean properties.
    `ScheduledExecutorTask(Runnable executorTask)` Create a new ScheduledExecutorTask, with default one-time execution without delay.
    `ScheduledExecutorTask(Runnable executorTask, long delay)` Create a new ScheduledExecutorTask, with default one-time execution with the given delay.
    `ScheduledExecutorTask(Runnable executorTask, long delay, long period, boolean fixedRate)` Create a new ScheduledExecutorTask.

  - ### 方法概要

    所有方法 实例方法 具体方法
    限定符和类型 | 方法和说明
    --- | ---
    `long` | `getDelay()` Return the delay before starting the job for the first time.
    `long` | `getPeriod()` Return the period between repeated task executions.
    `Runnable` | `getRunnable()` Return the Runnable to schedule as executor task.
    `TimeUnit` | `getTimeUnit()` Return the time unit for the delay and period values.
    `boolean` | `isFixedRate()` Return whether to schedule as fixed-rate execution.
    `boolean` | `isOneTimeTask()` Is this task only ever going to execute once?
    `void` | `setDelay(long delay)` Set the delay before starting the task for the first time, in milliseconds.
    `void` | `setFixedRate(boolean fixedRate)` Set whether to schedule as fixed-rate execution, rather than fixed-delay execution.
    `void` | `setPeriod(long period)` Set the period between repeated task executions, in milliseconds.
    `void` | `setRunnable(Runnable executorTask)` Set the Runnable to schedule as executor task.
    `void` | `setTimeUnit(TimeUnit timeUnit)` Specify the time unit for the delay and period values.

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

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

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

    - #### ScheduledExecutorTask

          public ScheduledExecutorTask()

      Create a new ScheduledExecutorTask, to be populated via bean properties.
      另请参阅:
        `setDelay(long)`, `setPeriod(long)`, `setFixedRate(boolean)`

    - #### ScheduledExecutorTask

          public ScheduledExecutorTask(Runnable executorTask)

      Create a new ScheduledExecutorTask, with default one-time execution without delay.
      参数:
        `executorTask` - the Runnable to schedule

    - #### ScheduledExecutorTask

          public ScheduledExecutorTask(Runnable executorTask,
                                       long delay)

      Create a new ScheduledExecutorTask, with default one-time execution with the given delay.
      参数:
        `executorTask` - the Runnable to schedule
        `delay` - the delay before starting the task for the first time (ms)

    - #### ScheduledExecutorTask

          public ScheduledExecutorTask(Runnable executorTask,
                                       long delay,
                                       long period,
                                       boolean fixedRate)

      Create a new ScheduledExecutorTask.
      参数:
        `executorTask` - the Runnable to schedule
        `delay` - the delay before starting the task for the first time (ms)
        `period` - the period between repeated task executions (ms)
        `fixedRate` - whether to schedule as fixed-rate execution

  - ### 方法详细资料

    - #### setRunnable

          public void setRunnable(Runnable executorTask)

      Set the Runnable to schedule as executor task.

    - #### getRunnable

          public Runnable getRunnable()

      Return the Runnable to schedule as executor task.

    - #### setDelay

          public void setDelay(long delay)

      Set the delay before starting the task for the first time, in milliseconds. Default is 0, immediately starting the task after successful scheduling.

    - #### getDelay

          public long getDelay()

      Return the delay before starting the job for the first time.

    - #### setPeriod

          public void setPeriod(long period)

      Set the period between repeated task executions, in milliseconds.

      Default is -1, leading to one-time execution. In case of a positive value, the task will be executed repeatedly, with the given interval in-between executions.

      Note that the semantics of the period value vary between fixed-rate and fixed-delay execution.

      Note: A period of 0 (for example as fixed delay) is not supported, simply because `java.util.concurrent.ScheduledExecutorService` itself does not support it. Hence a value of 0 will be treated as one-time execution; however, that value should never be specified explicitly in the first place!

      另请参阅:
        `setFixedRate(boolean)`, `isOneTimeTask()`, `ScheduledExecutorService.scheduleWithFixedDelay(Runnable, long, long, java.util.concurrent.TimeUnit)`

    - #### getPeriod

          public long getPeriod()

      Return the period between repeated task executions.

    - #### isOneTimeTask

          public boolean isOneTimeTask()

      Is this task only ever going to execute once?
      返回:
        `true` if this task is only ever going to execute once
      另请参阅:
        `getPeriod()`

    - #### setTimeUnit

          public void setTimeUnit(@Nullable
                                  TimeUnit timeUnit)

      Specify the time unit for the delay and period values. Default is milliseconds (`TimeUnit.MILLISECONDS`).
      另请参阅:
        `TimeUnit.MILLISECONDS`, `TimeUnit.SECONDS`

    - #### getTimeUnit

          public TimeUnit getTimeUnit()

      Return the time unit for the delay and period values.

    - #### setFixedRate

          public void setFixedRate(boolean fixedRate)

      Set whether to schedule as fixed-rate execution, rather than fixed-delay execution. Default is "false", that is, fixed delay.

      See ScheduledExecutorService javadoc for details on those execution modes.

      另请参阅:
        `ScheduledExecutorService.scheduleWithFixedDelay(java.lang.Runnable, long, long, java.util.concurrent.TimeUnit)`, `ScheduledExecutorService.scheduleAtFixedRate(java.lang.Runnable, long, long, java.util.concurrent.TimeUnit)`

    - #### isFixedRate

          public boolean isFixedRate()

      Return whether to schedule as fixed-rate execution.