- 6
- 0
- 约1.36万字
- 约 10页
- 2019-01-11 发布于湖北
- 举报
相信做软件的朋友都有这样的经历,我的软件是不是少了点什么东西呢?比如定时任务啊,
就拿新闻发布系统来说,如果新闻的数据更新太快,势必涉及一个问题,这些新闻不能由人工的去发布,应该让系统自己发布,这就需要用到定时定制任务了,以前定制任务无非就是设计一个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
- 超级房车赛汽车运动系统解析图文攻略.pdf
- 超级笑话大集合.doc
- 超简单7招 拍出最出彩雨季人像作品.doc
- 超临界W型火焰锅炉垂直水冷壁低质量流速条件下热敏感性研究.pdf
- 超临界超超临界锅炉用钢.doc
- 超强心算秘诀留着教孩子.pdf
- 超人背GRE词汇十天一万惊人词汇记忆一智课教育旗下智课教育.pdf
- 超日太阳独立董事2010年度述职报告 20110224.pdf
- 超细金属粉微波电磁性能研究.pdf
- 全过程工程管理造价咨询工程监理项目服务方案投标方案(技术部分).doc
- 招标代理服务投标技术服务方案(技术方案).doc
- AI大模型与AIGC技术在公安领域的应用解决方案(99页 PPT).pptx
- 工业4.0智能制造数字工厂规划方案.pptx
- 树立社会主义核心价值观.docx
- 三年(2023-2025)中考历史真题分类汇编(全国)专题21 科技文化与社会生活(解析版).docx
- 2025年中考道德与法治真题完全解读(吉林卷).pdf
- 2025年中考道德与法治真题完全解读(安徽卷).pdf
- 三年(2023-2025)中考历史真题分类汇编(全国)专题14 人民解放战争(解析版).pdf
- 三年(2023-2025)广东中考历史真题分类汇编:专题03 中国近代史(八年级上册)(解析版).docx
最近下载
- 期末专题复习书面表达满分范文必背10篇人教版英语八年级上册(1).docx VIP
- 2026天津市津南创腾经济开发有限公司招聘8人考试笔试参考题库及答案解析.docx VIP
- 四川省成都市双流区2024-2025学年八年级上学期期末历史试题(含答案).docx VIP
- 1岗位操作指南-管家V2.0(A4版)修订稿.pdf VIP
- 山东省菏泽市2024-2025学年高一上学期期末考试语文试题.pdf VIP
- 痤疮护理 ppt课件资料讲解.ppt VIP
- 服装品类商业计划书.pptx VIP
- (正式版)DB15∕T 3202-2023 《高纬度多年冻土区公路工程地质勘察技术规范》.docx VIP
- 160个风机特性曲线.docx VIP
- 月考试卷Unit3-4(试题)人教PEP版英语六年级上册.docx VIP
原创力文档

文档评论(0)