org.springframework.scheduling.config

## Class ScheduledTaskRegistrar

- java.lang.Object
- - org.springframework.scheduling.config.ScheduledTaskRegistrar

All Implemented Interfaces:
  DisposableBean, InitializingBean

Direct Known Subclasses:
  ContextLifecycleScheduledTaskRegistrar

    public class ScheduledTaskRegistrar
    extends Object
    implements InitializingBean, DisposableBean

Helper bean for registering tasks with a `TaskScheduler`, typically using cron expressions.

As of Spring 3.1, `ScheduledTaskRegistrar` has a more prominent user-facing role when used in conjunction with the @`EnableAsync` annotation and its `SchedulingConfigurer` callback interface.

Since:
  3.0
Author:
  Juergen Hoeller, Chris Beams
See Also:
  `EnableAsync`, `SchedulingConfigurer`

### Constructor Summary

Constructors
Constructor and Description
`ScheduledTaskRegistrar()`

### Method Summary

Methods
`void` `addCronTask(CronTask task)` Add a `CronTask`.
`void` `addCronTask(Runnable task, String expression)` Add a Runnable task to be triggered per the given cron expression
`void` `addFixedDelayTask(IntervalTask task)` Add a fixed-delay `IntervalTask`.
`void` `addFixedDelayTask(Runnable task, long delay)` Add a Runnable task to be triggered with the given fixed delay.
`void` `addFixedRateTask(IntervalTask task)` Add a fixed-rate `IntervalTask`.
`void` `addFixedRateTask(Runnable task, long period)` Add a Runnable task to be triggered at the given fixed-rate period.
`void` `addTriggerTask(Runnable task, Trigger trigger)` Add a Runnable task to be triggered per the given `Trigger`.
`void` `addTriggerTask(TriggerTask task)` Add a `TriggerTask`.
`void` `afterPropertiesSet()` Calls `scheduleTasks()` at bean construction time.
`void` `destroy()` Invoked by a BeanFactory on destruction of a singleton.
`TaskScheduler` `getScheduler()` Return the `TaskScheduler` instance for this registrar (may be `null`).
`boolean` `hasTasks()` Return whether this `ScheduledTaskRegistrar` has any tasks registered.
`protected void` `scheduleTasks()` Schedule all registered tasks against the underlying task scheduler.
`void` `setCronTasks(Map<Runnable,String> cronTasks)` Specify triggered tasks as a Map of Runnables (the tasks) and cron expressions.
`void` `setCronTasksList(List<CronTask> cronTasks)` Specify triggered tasks as a list of `CronTask` objects.
`void` `setFixedDelayTasks(Map<Runnable,Long> fixedDelayTasks)` Specify triggered tasks as a Map of Runnables (the tasks) and fixed-delay values.
`void` `setFixedDelayTasksList(List<IntervalTask> fixedDelayTasks)` Specify fixed-delay tasks as a list of `IntervalTask` objects.
`void` `setFixedRateTasks(Map<Runnable,Long> fixedRateTasks)` Specify triggered tasks as a Map of Runnables (the tasks) and fixed-rate values.
`void` `setFixedRateTasksList(List<IntervalTask> fixedRateTasks)` Specify fixed-rate tasks as a list of `IntervalTask` objects.
`void` `setScheduler(Object scheduler)` Set the `TaskScheduler` to register scheduled tasks with, or a `ScheduledExecutorService` to be wrapped as a `TaskScheduler`.
`void` `setTaskScheduler(TaskScheduler taskScheduler)` Set the `TaskScheduler` to register scheduled tasks with.
`void` `setTriggerTasks(Map<Runnable,Trigger> triggerTasks)` Specify triggered tasks as a Map of Runnables (the tasks) and Trigger objects (typically custom implementations of the `Trigger` interface).
`void` `setTriggerTasksList(List<TriggerTask> triggerTasks)` Specify triggered tasks as a list of `TriggerTask` objects.

### Methods inherited from class java.lang.Object

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

### Constructor Detail

#### ScheduledTaskRegistrar

    public ScheduledTaskRegistrar()

### Method Detail

#### setTaskScheduler

    public void setTaskScheduler(TaskScheduler taskScheduler)

Set the `TaskScheduler` to register scheduled tasks with.

#### setScheduler

    public void setScheduler(Object scheduler)

Set the `TaskScheduler` to register scheduled tasks with, or a `ScheduledExecutorService` to be wrapped as a `TaskScheduler`.

#### getScheduler

    public TaskScheduler getScheduler()

Return the `TaskScheduler` instance for this registrar (may be `null`).

#### setTriggerTasks

    public void setTriggerTasks(Map<Runnable,Trigger> triggerTasks)

Specify triggered tasks as a Map of Runnables (the tasks) and Trigger objects (typically custom implementations of the `Trigger` interface).

#### setTriggerTasksList

    public void setTriggerTasksList(List<TriggerTask> triggerTasks)

Specify triggered tasks as a list of `TriggerTask` objects. Primarily used by `<task:*>` namespace parsing.

Since:
  3.2
See Also:
  `ScheduledTasksBeanDefinitionParser`

#### setCronTasks

    public void setCronTasks(Map<Runnable,String> cronTasks)

Specify triggered tasks as a Map of Runnables (the tasks) and cron expressions.

See Also:
  `CronTrigger`

#### setCronTasksList

    public void setCronTasksList(List<CronTask> cronTasks)

Specify triggered tasks as a list of `CronTask` objects. Primarily used by `<task:*>` namespace parsing.

Since:
  3.2
See Also:
  `ScheduledTasksBeanDefinitionParser`

#### setFixedRateTasks

    public void setFixedRateTasks(Map<Runnable,Long> fixedRateTasks)

Specify triggered tasks as a Map of Runnables (the tasks) and fixed-rate values.

See Also:
  `TaskScheduler.scheduleAtFixedRate(Runnable, long)`

#### setFixedRateTasksList

    public void setFixedRateTasksList(List<IntervalTask> fixedRateTasks)

Specify fixed-rate tasks as a list of `IntervalTask` objects. Primarily used by `<task:*>` namespace parsing.

Since:
  3.2
See Also:
  `ScheduledTasksBeanDefinitionParser`

#### setFixedDelayTasks

    public void setFixedDelayTasks(Map<Runnable,Long> fixedDelayTasks)

Specify triggered tasks as a Map of Runnables (the tasks) and fixed-delay values.

See Also:
  `TaskScheduler.scheduleWithFixedDelay(Runnable, long)`

#### setFixedDelayTasksList

    public void setFixedDelayTasksList(List<IntervalTask> fixedDelayTasks)

Specify fixed-delay tasks as a list of `IntervalTask` objects. Primarily used by `<task:*>` namespace parsing.

Since:
  3.2
See Also:
  `ScheduledTasksBeanDefinitionParser`

#### addTriggerTask

    public void addTriggerTask(Runnable task,
                      Trigger trigger)

Add a Runnable task to be triggered per the given `Trigger`.

See Also:
  `TaskScheduler.scheduleAtFixedRate(Runnable, long)`

#### addTriggerTask

    public void addTriggerTask(TriggerTask task)

Add a `TriggerTask`.

Since:
  3.2
See Also:
  `TaskScheduler.scheduleAtFixedRate(Runnable, long)`

#### addCronTask

    public void addCronTask(Runnable task,
                   String expression)

Add a Runnable task to be triggered per the given cron expression

#### addCronTask

    public void addCronTask(CronTask task)

Add a `CronTask`.

Since:
  3.2

#### addFixedRateTask

    public void addFixedRateTask(Runnable task,
                        long period)

Add a Runnable task to be triggered at the given fixed-rate period.

See Also:
  `TaskScheduler.scheduleAtFixedRate(Runnable, long)`

#### addFixedRateTask

    public void addFixedRateTask(IntervalTask task)

Add a fixed-rate `IntervalTask`.

Since:
  3.2
See Also:
  `TaskScheduler.scheduleAtFixedRate(Runnable, long)`

#### addFixedDelayTask

    public void addFixedDelayTask(Runnable task,
                         long delay)

Add a Runnable task to be triggered with the given fixed delay.

See Also:
  `TaskScheduler.scheduleWithFixedDelay(Runnable, long)`

#### addFixedDelayTask

    public void addFixedDelayTask(IntervalTask task)

Add a fixed-delay `IntervalTask`.

Since:
  3.2
See Also:
  `TaskScheduler.scheduleWithFixedDelay(Runnable, long)`

#### hasTasks

    public boolean hasTasks()

Return whether this `ScheduledTaskRegistrar` has any tasks registered.

Since:
  3.2

#### afterPropertiesSet

    public void afterPropertiesSet()

Calls `scheduleTasks()` at bean construction time.

Specified by:
  `afterPropertiesSet` in interface `InitializingBean`

#### scheduleTasks

    protected void scheduleTasks()

Schedule all registered tasks against the underlying task scheduler.

#### destroy

    public void destroy()

Description copied from interface: `DisposableBean`
Invoked by a BeanFactory on destruction of a singleton.

Specified by:
  `destroy` in interface `DisposableBean`