WEB.XML中加载定时器的配置方式
来源:互联网 发布:仿卷皮淘宝客源码 编辑:程序博客网 时间:2024/05/21 01:43
将不同的业务继承任务,定时器执行的时候只需要执行一个任务即可。
创建servlet,重写init(),service(),destroy()方法,初始化创建 并且启动定时器。
private Timer timer1 = null;
public void init(){
timer1=new Timer().schedule(new TimerTask(){
public void run() {
//执行task
}
},开始时间,间隔时间);
}
service()什么也不干
destroy销毁定时器
public void destroy() {
super.destroy();
if(timer1!=null){
timer1.cancel();
}
}
配置WEB.XML:
第一种方式:
设置每15分钟运行的Servlet
<servlet name='alarm' servlet-class='test.TestAlarm'>
<run-at>:00, :15, :30, :45</run-at>
</servlet>
设置每天16:30和20:00运行的Servlet
<servlet name='alarm' servlet-class='test.TestAlarm'>
<run-at>16:30,20:00</run-at>
</servlet>
第二种方式:
在servlet配置中增加 < load-on-startup >555< /load-on-startup > 这个数字越高,优先级越低,负数表示不自动加载
//以下例子通过定时器改变另一个定时器的延迟执行的时间
public class test {public static void main(String[] args) {/*String ss="cmsIm/chatlog";System.out.println(File.separator);ss=ss.replaceAll("\\/","\\"+File.separator);System.out.println(ss);*/final Date firstDate=new Date();A a=new A();//计算延迟时间的定时器new Timer().schedule(a,firstDate,1000*60);//执行任务的定时器new Timer().schedule(new TimerTask(){public void run() {System.out.println("执行任务!"+A.delay);}},firstDate,A.delay);}}class A extends TimerTask{public static long delay=1000*10;public void run(){delay+=1000;}}
- WEB.XML中加载定时器的配置方式
- web.xml中配置定时器
- spring的配置文件在web.xml中加载的方式
- web.xml中配置url-pattern的几种方式
- web.xml中配置spring的几种方式
- web.xml中配置spring的几种方式
- web.xml中配置spring的几种方式
- web.xml 中配置加载顺序
- springMVC web.xml 中配置加载顺序
- web.xml 配置定时器 详解
- web.xml中各种配置方式
- web.xml中配置spring的几种方式 spring spring web.xml
- web.xml中配置spring的几种方式 spring spring web.xml
- web中TImer定时器的使用(web.xml)
- 加载Spring的 Web.xml配置
- web.xml的配置及加载顺序
- Web.xml的配置及加载
- web.xml各个配置的加载顺序
- KM算法总结
- Linux网络协议栈(四)——链路层(2)
- SIFT 特征提取算法总结
- Linux 用户和用户组 配置说明
- 用sysctl调整linux内核选项
- WEB.XML中加载定时器的配置方式
- 腾讯一道面试题
- cocos2d-x code 254错误
- Mac下Chrome和遨游浏览器的快捷键
- Magento: The Best Solution to Ugrade Magento from 1.5.x.x – 1.7.x.x
- linux GCC常用命令
- EOS流程配置出现审批不同意的几大主要原因
- poj 2570 Fiber Network (两种解法 1.floyd+位操作 2.传递闭包)
- jsoup selelct 选择器