Spring定时器的使用
2015-12-24 10:28
459 查看
<?xml version="1.0"
encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<!--
自动启动 -->
<property
name="autoStartup">
<value>true</value>
</property>
<property
name="triggers">
<list>
<ref
local="testTrigger" />
</list>
</property>
</bean>
<bean id="testTrigger"
class="org.springframework.scheduling.quartz.CronTriggerBean">
<property
name="jobDetail">
<ref
bean="testJobDetail" />
</property>
<property
name="cronExpression">
<!--
过一秒开始,每间隔两秒执行 -->
<value>1/2
* * * * ?</value>
</property>
</bean>
<bean id="testJobDetail"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property
name="targetObject">
<ref
bean="scheduleTimerTest" />
</property>
<property
name="targetMethod">
<value>timeTest</value>
</property>
<property
name="concurrent" value="false" />
</bean>
<bean id="scheduleTimerTest"
class="com.lrq.timer.ScheduleTimerTest"></bean>
</beans>
这是配置文件,引入即可:
需要注意的地方:
1
jar包问题:ssh+\spring-context-support-3.2.1.RELEASE.jar+quartz-1.6.6.jar+quartz-all-1.6.6.jar
配置文件:
1 <bean id="scheduleTimerTest"
class="com.lrq.timer.ScheduleTimerTest"></bean>需要定时器执行的目标类;
需要被上面的定时器引用:
<property
name="targetObject">
<ref
bean="scheduleTimerTest" />
</property>
<property
name="targetMethod">
<value>timeTest</value>
</property>
2执行周期匹配表达式;请参看文档;
核心思路还是依赖注入;
![](http://b.bst.126.net/newpage/images/microblog.png?1)
转发至微博
![](http://b.bst.126.net/newpage/images/microblog.png?1)
转发至微博
相关文章推荐
- struts总结完整整理版
- struts2总结:草稿
- Spring的总结
- struts2中默认拦截器栈中的拦截器…
- Java内存分析(转载)
- Struts2之Action处理多个方法总结
- Spring框架所有技术笔记总结
- JavaWeb基础回顾
- Struts2的笔记整理与复习
- Struts2.3.7技术的汇总之六(权限…
- 黑马程序员--Struts2.3.7技术的汇…
- 黑马程序员--Struts2.3.7技术的汇…
- 黑马程序员--Struts2.3.7技术的汇…
- Struts2.3.7技术的汇总之三(类型…
- Struts2.3.7技术的汇总之二(注册…
- 黑马程序员--Struts2的常量
- 黑马程序员--Struts2复习笔记
- JDK1.5并发库笔记和总结
- Java一些实用的类(持续更新)
- Java多线程基础知识回顾与总结;