定时任务总结

时间:2022-01-21 07:46:31

一,在xml配置文件中配置定时任务和触发器

<!--配置定时任务->

<pre name="code" class="html"><bean id="readFile"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"
p:targetObject-ref="taskService" p:targetMethod="readFile" />
<bean id="readFileTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"
p:jobDetail-ref="readFile" p:cronExpression="0 0 5 * * ?" />

 
<!-- 定时任务触发器列表 -->   
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref local="readFileTrigger" />
</list>
</property>
</bean>

二,写定时任务方法

TaskService.java

public class TaskService {

public void readFile() {

}
}