spring 定时任务
import java.util.TimerTask; import com.iss.common.util.CommonMethods; import com.iss.common.util.Log4jLogger; /** * @ClassName: SpringTask * @Description: spring 定时器 * @author wenjianhai * @date 2011-5-20 上午11:18:03 * @version V1.0 */ public class SpringTask extends TimerTask { private static Log4jLogger log = Log4jLogger.getLogger(SpringTask.class); private static final String FILE_PATH = "D:\\soft\\OTM"; /** (非 Javadoc) * <p>Title: run</p> * <p>Description: 运行定时任务,删除 D:\\soft\\OTM下的文件</p> * @see java.util.TimerTask#run() */ @Override public void run() { log.info("----- start execute SpringTask -----"); CommonMethods.deleteFiles(FILE_PATH); log.info("----- end execute SpringTask -----"); } } 在 spring 核心配置文件中: <!-- spring 定时任务 --> <bean id="springTask" class="com.iss.common.task.SpringTask" /> <!-- 配置定时器 --> <bean id="scheduleReportTask" class="org.springframework.scheduling.timer.ScheduledTimerTask"> <!-- 告诉ScheduledTimerTask运行哪个任务 --> <property name="timerTask" ref="springTask" /> <!-- 运行间隔时间 --> <property name="period"> <!-- 每隔24小时运行一次(毫秒ms)--> <value>86400000</value> </property> <!-- 延迟启动(毫秒ms) 指定当任务第一次运行之前应该等多久 --> <property name="delay"> <!-- 5秒 --> <value>5000</value> </property> </bean> <!-- 启动定时器 --> <bean class="org.springframework.scheduling.timer.TimerFactoryBean"> <property name="scheduledTimerTasks"> <list> <ref bean="scheduleReportTask"/> </list> </property> </bean>
相关推荐
yupi0 2020-10-10
spring 2020-08-18
编程点滴 2020-07-29
幸运小侯子 2020-07-05
itjavashuai 2020-07-04
qingjiuquan 2020-06-29
shushan 2020-06-25
小鱿鱼 2020-06-22
咻pur慢 2020-06-18
melonjj 2020-06-17
qingjiuquan 2020-06-13
neweastsun 2020-06-05
小鱿鱼 2020-06-05
mxcsdn 2020-05-31
吾日五省我身 2020-05-27
牧场SZShepherd 2020-05-27
sweetgirl0 2020-05-14