面我们来看一下Spring中提供的定时任务开发:
在Spring中开发定时任务,分为3个步骤。
1 创建定时任务
2 注册定时任务
3 启动定时任务
分别来看一下
1 创建定时任务:
package org.jnotnull;
import java.util.TimerTask;
public class MyTesk extends TimerTask{
....
public void run(){
//添加任务
}
....
}
2 注册定时任务,并设置参数
我们来配置TimerConfig.xml防御WEB-INF下
class="org.springframework.scheduling.timer.ScheduledTimerTask">
20000
30000
class="org.springframework.scheduling.timer.TimerFactoryBean">
3 启动定时任务
contextConfigLocation
http://www.bt285.cn /WEB-INF/TimerConfig.xml
org.springframework.web.context.ContextLoaderListener
下面我们再来看看在Spring中如何使用Quartz实现定时功能
1 创建定时任务:
package org.jnotnull;
import java.util.TimerTask;
/**
*http://www.5a520.cn
*/
public class MyTesk extends TimerTask{
public void excute(){
//添加任务
}
.
}
2 注册定时任务,并设置参数
我们来配置TimerConfig.xml防御WEB-INF下
"http://www.springframework.org/dtd/spring-beans.dtd">
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
[ ]
execute
[ ]
12,23****?
class="org.springframework.scheduling.quartz.ScheduleFactoryBean">
3 启动定时任务
contextConfigLocation
http://www.bt285.cn /WEB-INF/TimerConfig.xml
org.springframework.web.context.ContextLoaderListener
本文作者:不详 来源:网络
CIO之家 www.ciozj.com 微信公众号:imciow