- 1
- 0
- 约1.36万字
- 约 10页
- 2018-08-04 发布于福建
- 举报
彻底理解spring定制任务
相信做软件的朋友都有这样的经历,我的软件是不是少了点什么东西呢?比如定时任务啊,
就拿新闻发布系统来说,如果新闻的数据更新太快,势必涉及一个问题,这些新闻不能由人工的去发布,应该让系统自己发布,这就需要用到定时定制任务了,以前定制任务无非就是设计一个Thread,并且设置运行时间片,让它到了那个时间执行一次,就ok了,让系统启动的时候启动它,想来也够简单的。不过有了spring,我想这事情就更简单了。
看看spring的配置文件,想来就只有这个配置文件了
xml 代码
bean id=infoCenterAutoBuildTask
class=com.teesoo.teanet.scheduling.InfoCenterAutoBuildTask
property name=baseService ref=baseService /
property name=htmlCreator ref=htmlCreator /
/bean
bean id=scheduledTask
class=org.springframework.scheduling.timer.ScheduledTimerTask
!-- wait 10 seconds before starting repeated execution --
property name=delay value=10000 /
!-- run every 50 seconds --
property name=period value=1000000 /
property name=timerTask ref=infoCenterAutoBuildTask /
/bean
bean id=timerFactory class=org.springframework.scheduling.timer.TimerFactoryBean
property name=scheduledTimerTasks
list
!-- see the example above --
ref bean=scheduledTask /
/list
/property
/bean
上面三个配置文件中只有一个配置文件是涉及到您自己的class的,其他的都是spring的类。很简单吧
我们只需要涉及一个class让他继承java.util.TimerTask;
java 代码
BaseTask extends java.util.TimerTask {
//用户只需要实现这个方面,把自己的任务放到这里
public void run(){
System.out.in(do yuor things...);
}
}
下面让我们来看看 spring的源代码
java 代码
/*
* Copyright 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* /licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.scheduling.timer;
im
您可能关注的文档
最近下载
- 国就有成人演出的电影了?想看就要冒生命危险.pdf VIP
- 综合素质练习题及答案.doc VIP
- 2020-2021学年北京高三化学二轮复习 反应原理型简答题(突破二卷)(word版 含答案).docx VIP
- 电力拖动控制线路安装与检修(白银矿冶职业技术学院)知到智慧树答案.docx VIP
- 煤炭巷道掘砌工(高级工)资格考试题库(全真题库).docx VIP
- 影像叙事中情感共鸣生成机制.docx VIP
- 同轴二级圆柱齿轮减速器的设计(硬齿面).doc VIP
- 基于GPU多线程多通道图像高速重构方法、设备及介质.pdf VIP
- 毕业设计(论文)-MMD625双齿辊破碎机设计.docx VIP
- 中小型企业招聘管理研究——以三都港海鲜食品有限公司为例.docx
原创力文档

文档评论(0)