类 ScheduledTaskRegistrar
- java.lang.Object
- org.springframework.scheduling.config.ScheduledTaskRegistrar
- 所有已实现的接口:
DisposableBean,InitializingBean,ScheduledTaskHolder
public class ScheduledTaskRegistrar extends Object implements ScheduledTaskHolder, InitializingBean, DisposableBean
Helper bean for registering tasks with aTaskScheduler, typically using cron expressions.As of Spring 3.1,
ScheduledTaskRegistrarhas a more prominent user-facing role when used in conjunction with the@EnableAsyncannotation and itsSchedulingConfigurercallback interface.- 从以下版本开始:
- 3.0
- 作者:
- Juergen Hoeller, Chris Beams, Tobias Montagna-Hay, Sam Brannen
- 另请参阅:
EnableAsync,SchedulingConfigurer
字段概要
字段 修饰符和类型 字段 说明 static StringCRON_DISABLEDA special cron expression value that indicates a disabled trigger: "-".
构造器概要
构造器 构造器 说明 ScheduledTaskRegistrar()
方法概要
所有方法 实例方法 具体方法 已过时的方法 修饰符和类型 方法 说明 voidaddCronTask(Runnable task, String expression)Add aRunnabletask to be triggered per the given cronexpression.voidaddCronTask(CronTask task)Add aCronTask.voidaddFixedDelayTask(Runnable task, long delay)Add a Runnable task to be triggered with the given fixed delay.voidaddFixedDelayTask(IntervalTask task)Add a fixed-delayIntervalTask.voidaddFixedRateTask(Runnable task, long interval)Add aRunnabletask to be triggered at the given fixed-rate interval.voidaddFixedRateTask(IntervalTask task)Add a fixed-rateIntervalTask.voidaddTriggerTask(Runnable task, Trigger trigger)Add a Runnable task to be triggered per the givenTrigger.voidaddTriggerTask(TriggerTask task)Add aTriggerTask.voidafterPropertiesSet()CallsscheduleTasks()at bean construction time.voiddestroy()Invoked by the containingBeanFactoryon destruction of a bean.List<CronTask>getCronTaskList()Get the cron tasks as an unmodifiable list ofCronTaskobjects.List<IntervalTask>getFixedDelayTaskList()Get the fixed-delay tasks as an unmodifiable list ofIntervalTaskobjects.List<IntervalTask>getFixedRateTaskList()Get the fixed-rate tasks as an unmodifiable list ofIntervalTaskobjects.Set<ScheduledTask>getScheduledTasks()Return all locally registered tasks that have been scheduled by this registrar.TaskSchedulergetScheduler()Return theTaskSchedulerinstance for this registrar (may benull).List<TriggerTask>getTriggerTaskList()Get the trigger tasks as an unmodifiable list ofTriggerTaskobjects.booleanhasTasks()Return whether thisScheduledTaskRegistrarhas any tasks registered.ScheduledTaskscheduleCronTask(CronTask task)Schedule the specified cron task, either right away if possible or on initialization of the scheduler.ScheduledTaskscheduleFixedDelayTask(FixedDelayTask task)Schedule the specified fixed-delay task, either right away if possible or on initialization of the scheduler.ScheduledTaskscheduleFixedDelayTask(IntervalTask task)已过时。as of 5.0.2, in favor ofscheduleFixedDelayTask(FixedDelayTask)ScheduledTaskscheduleFixedRateTask(FixedRateTask task)Schedule the specified fixed-rate task, either right away if possible or on initialization of the scheduler.ScheduledTaskscheduleFixedRateTask(IntervalTask task)已过时。as of 5.0.2, in favor ofscheduleFixedRateTask(FixedRateTask)protected voidscheduleTasks()Schedule all registered tasks against the underlying task scheduler.ScheduledTaskscheduleTriggerTask(TriggerTask task)Schedule the specified trigger task, either right away if possible or on initialization of the scheduler.voidsetCronTasks(Map<Runnable,String> cronTasks)Specify triggered tasks as a Map of Runnables (the tasks) and cron expressions.voidsetCronTasksList(List<CronTask> cronTasks)Specify triggered tasks as a list ofCronTaskobjects.voidsetFixedDelayTasks(Map<Runnable,Long> fixedDelayTasks)Specify triggered tasks as a Map of Runnables (the tasks) and fixed-delay values.voidsetFixedDelayTasksList(List<IntervalTask> fixedDelayTasks)Specify fixed-delay tasks as a list ofIntervalTaskobjects.voidsetFixedRateTasks(Map<Runnable,Long> fixedRateTasks)Specify triggered tasks as a Map of Runnables (the tasks) and fixed-rate values.voidsetFixedRateTasksList(List<IntervalTask> fixedRateTasks)Specify fixed-rate tasks as a list ofIntervalTaskobjects.voidsetScheduler(Object scheduler)Set theTaskSchedulerto register scheduled tasks with, or aScheduledExecutorServiceto be wrapped as aTaskScheduler.voidsetTaskScheduler(TaskScheduler taskScheduler)Set theTaskSchedulerto register scheduled tasks with.voidsetTriggerTasks(Map<Runnable,Trigger> triggerTasks)Specify triggered tasks as a Map of Runnables (the tasks) and Trigger objects (typically custom implementations of theTriggerinterface).voidsetTriggerTasksList(List<TriggerTask> triggerTasks)Specify triggered tasks as a list ofTriggerTaskobjects.
字段详细资料
CRON_DISABLED
public static final String CRON_DISABLED
A special cron expression value that indicates a disabled trigger: "-".This is primarily meant for use with
addCronTask(Runnable, String)when the value for the suppliedexpressionis retrieved from an external source — for example, from a property in theEnvironment.- 从以下版本开始:
- 5.2
- 另请参阅:
Scheduled.CRON_DISABLED, 常量字段值
构造器详细资料
ScheduledTaskRegistrar
public ScheduledTaskRegistrar()
方法详细资料
setTaskScheduler
public void setTaskScheduler(TaskScheduler taskScheduler)
Set theTaskSchedulerto register scheduled tasks with.
setScheduler
public void setScheduler(@Nullable Object scheduler)
Set theTaskSchedulerto register scheduled tasks with, or aScheduledExecutorServiceto be wrapped as aTaskScheduler.
getScheduler
@Nullable public TaskScheduler getScheduler()
Return theTaskSchedulerinstance for this registrar (may benull).
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 theTriggerinterface).
setTriggerTasksList
public void setTriggerTasksList(List<TriggerTask> triggerTasks)
Specify triggered tasks as a list ofTriggerTaskobjects. Primarily used by<task:*>namespace parsing.- 从以下版本开始:
- 3.2
- 另请参阅:
ScheduledTasksBeanDefinitionParser
getTriggerTaskList
public List<TriggerTask> getTriggerTaskList()
Get the trigger tasks as an unmodifiable list ofTriggerTaskobjects.- 返回:
- the list of tasks (never
null) - 从以下版本开始:
- 4.2
setCronTasks
public void setCronTasks(Map<Runnable,String> cronTasks)
Specify triggered tasks as a Map of Runnables (the tasks) and cron expressions.- 另请参阅:
CronTrigger
setCronTasksList
public void setCronTasksList(List<CronTask> cronTasks)
Specify triggered tasks as a list ofCronTaskobjects. Primarily used by<task:*>namespace parsing.- 从以下版本开始:
- 3.2
- 另请参阅:
ScheduledTasksBeanDefinitionParser
getCronTaskList
public List<CronTask> getCronTaskList()
Get the cron tasks as an unmodifiable list ofCronTaskobjects.- 返回:
- the list of tasks (never
null) - 从以下版本开始:
- 4.2
setFixedRateTasks
public void setFixedRateTasks(Map<Runnable,Long> fixedRateTasks)
Specify triggered tasks as a Map of Runnables (the tasks) and fixed-rate values.
setFixedRateTasksList
public void setFixedRateTasksList(List<IntervalTask> fixedRateTasks)
Specify fixed-rate tasks as a list ofIntervalTaskobjects. Primarily used by<task:*>namespace parsing.- 从以下版本开始:
- 3.2
- 另请参阅:
ScheduledTasksBeanDefinitionParser
getFixedRateTaskList
public List<IntervalTask> getFixedRateTaskList()
Get the fixed-rate tasks as an unmodifiable list ofIntervalTaskobjects.- 返回:
- the list of tasks (never
null) - 从以下版本开始:
- 4.2
setFixedDelayTasks
public void setFixedDelayTasks(Map<Runnable,Long> fixedDelayTasks)
Specify triggered tasks as a Map of Runnables (the tasks) and fixed-delay values.
setFixedDelayTasksList
public void setFixedDelayTasksList(List<IntervalTask> fixedDelayTasks)
Specify fixed-delay tasks as a list ofIntervalTaskobjects. Primarily used by<task:*>namespace parsing.- 从以下版本开始:
- 3.2
- 另请参阅:
ScheduledTasksBeanDefinitionParser
getFixedDelayTaskList
public List<IntervalTask> getFixedDelayTaskList()
Get the fixed-delay tasks as an unmodifiable list ofIntervalTaskobjects.- 返回:
- the list of tasks (never
null) - 从以下版本开始:
- 4.2
addTriggerTask
public void addTriggerTask(Runnable task, Trigger trigger)
Add a Runnable task to be triggered per the givenTrigger.
addTriggerTask
public void addTriggerTask(TriggerTask task)
Add aTriggerTask.- 从以下版本开始:
- 3.2
- 另请参阅:
TaskScheduler.scheduleAtFixedRate(Runnable, long)
addCronTask
public void addCronTask(Runnable task, String expression)
Add aRunnabletask to be triggered per the given cronexpression.As of Spring Framework 5.2, this method will not register the task if the
expressionis equal toCRON_DISABLED.
addCronTask
public void addCronTask(CronTask task)
Add aCronTask.- 从以下版本开始:
- 3.2
addFixedRateTask
public void addFixedRateTask(Runnable task, long interval)
Add aRunnabletask to be triggered at the given fixed-rate interval.
addFixedRateTask
public void addFixedRateTask(IntervalTask task)
Add a fixed-rateIntervalTask.- 从以下版本开始:
- 3.2
- 另请参阅:
TaskScheduler.scheduleAtFixedRate(Runnable, long)
addFixedDelayTask
public void addFixedDelayTask(Runnable task, long delay)
Add a Runnable task to be triggered with the given fixed delay.
addFixedDelayTask
public void addFixedDelayTask(IntervalTask task)
Add a fixed-delayIntervalTask.- 从以下版本开始:
- 3.2
- 另请参阅:
TaskScheduler.scheduleWithFixedDelay(Runnable, long)
hasTasks
public boolean hasTasks()
Return whether thisScheduledTaskRegistrarhas any tasks registered.- 从以下版本开始:
- 3.2
afterPropertiesSet
public void afterPropertiesSet()
CallsscheduleTasks()at bean construction time.- 指定者:
afterPropertiesSet在接口中InitializingBean
scheduleTasks
protected void scheduleTasks()
Schedule all registered tasks against the underlying task scheduler.
scheduleTriggerTask
@Nullable public ScheduledTask scheduleTriggerTask(TriggerTask task)
Schedule the specified trigger task, either right away if possible or on initialization of the scheduler.- 返回:
- a handle to the scheduled task, allowing to cancel it
- 从以下版本开始:
- 4.3
scheduleCronTask
@Nullable public ScheduledTask scheduleCronTask(CronTask task)
Schedule the specified cron task, either right away if possible or on initialization of the scheduler.- 返回:
- a handle to the scheduled task, allowing to cancel it (or
nullif processing a previously registered task) - 从以下版本开始:
- 4.3
scheduleFixedRateTask
@Deprecated @Nullable public ScheduledTask scheduleFixedRateTask(IntervalTask task)
已过时。as of 5.0.2, in favor ofscheduleFixedRateTask(FixedRateTask)Schedule the specified fixed-rate task, either right away if possible or on initialization of the scheduler.- 返回:
- a handle to the scheduled task, allowing to cancel it (or
nullif processing a previously registered task) - 从以下版本开始:
- 4.3
scheduleFixedRateTask
@Nullable public ScheduledTask scheduleFixedRateTask(FixedRateTask task)
Schedule the specified fixed-rate task, either right away if possible or on initialization of the scheduler.- 返回:
- a handle to the scheduled task, allowing to cancel it (or
nullif processing a previously registered task) - 从以下版本开始:
- 5.0.2
scheduleFixedDelayTask
@Deprecated @Nullable public ScheduledTask scheduleFixedDelayTask(IntervalTask task)
已过时。as of 5.0.2, in favor ofscheduleFixedDelayTask(FixedDelayTask)Schedule the specified fixed-delay task, either right away if possible or on initialization of the scheduler.- 返回:
- a handle to the scheduled task, allowing to cancel it (or
nullif processing a previously registered task) - 从以下版本开始:
- 4.3
scheduleFixedDelayTask
@Nullable public ScheduledTask scheduleFixedDelayTask(FixedDelayTask task)
Schedule the specified fixed-delay task, either right away if possible or on initialization of the scheduler.- 返回:
- a handle to the scheduled task, allowing to cancel it (or
nullif processing a previously registered task) - 从以下版本开始:
- 5.0.2
getScheduledTasks
public Set<ScheduledTask> getScheduledTasks()
Return all locally registered tasks that have been scheduled by this registrar.
destroy
public void destroy()
从接口复制的说明:DisposableBeanInvoked by the containingBeanFactoryon destruction of a bean.- 指定者:
destroy在接口中DisposableBean