<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-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/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd "> <!-- 要调用的工作类 --> <bean id="synchronizeGameInfo" class="com.cyou.gamehistory.trigger.SynchronizeGameInfo"> </bean> <!-- 定义调用对象和调用对象的方法 --> <bean id="updateGameInfo" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject" ref="synchronizeGameInfo" /> <property name="targetMethod" value="synchronizeGame" /> <!-- 非并发 --> <property name="concurrent" value="false" /> </bean> <!-- 定义触发时间 --> <bean id="updateGameTrigger" lazy-init="false" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail" ref="updateGameInfo"></property> <property name="cronExpression"> <!-- 每周星期天凌晨1点实行一次 --> <value>0 0 1 ? * L</value> </property> </bean> <!-- 总管理类 --> <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <ref local="updateGameTrigger"/> </list> </property> <property name="quartzProperties"> <props> <prop key="org.quartz.threadPool.threadCount">1</prop> </props> </property> </bean> </beans>
第一步,在Spring配置文件中增加本业务类
<bean id="synchronizeGameInfo" class="com.cyou.gamehistory.trigger.SynchronizeGameInfo">
第二步,定义任务。在Spring配置文件中配置代理类MethodInvokingJobDetailFactoryBean,定义任务的详细信息。
<bean id="updateGameInfo" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject" ref="synchronizeGameInfo" /> <property name="targetMethod" value="synchronizeGame" /> <!-- 非并发 --> <property name="concurrent" value="false" /> </bean>
这个配置告诉Spring,我们的任务是执行id为synchronizeGameInfo的bean中的synchronizeGame函数。其中参数concurrent告诉Spring,不要并发运行这个任务。
第三步,配置一个触发器。在Spring配置文件中配置触发器类updateGameTrigger。
<bean id="updateGameTrigger" lazy-init="false" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail" ref="updateGameInfo"></property> <property name="cronExpression"> <!-- 每周星期天凌晨1点实行一次 --> <value>0 0 1 ? * L</value> </property> </bean>
触发器将告诉Quartz两件事:在何时触发任务、触发哪个任务。其中属性参数cronExpression为调度时间,格式和unix上的crontab类似,其中问号表示忽略该位置(星期)上的值。属性参数jobDetail指向具体的任务bean:updateGameInfo 。如果你有多个任务,每个任务的触发时间都不一样,则你可以在此配置多个不同的触发器。
第四步,配置一个调度器。在Spring配置文件中配置调度器类SchedulerFactoryBean。
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <ref local="updateGameTrigger"/> </list> </property> <property name="quartzProperties"> <props> <prop key="org.quartz.threadPool.threadCount">1</prop> </props> </property> </bean>
该调度器用于管理触发器。只有在调度器中列表出现的触发器才被Quartz系统调度执行。至此,所有的配置已完成,任务已能正常跑了。
相关推荐
NULL 博文链接:https://javaeedevelop.iteye.com/blog/1540461
java + quartz实现定时任务,实现集群配置,在集群环境下多节点运行定时Quartz定任务,就会存在重复处理任务的现象,为解决这一问题,下面我将介绍使用 Quartz 的 TASK ( 12 张表)实例化到数据库,基于数据库自动...
Quartz学习文档 Spring + Quartz配置详细实例 jar包 Quartz时间格式设置
Spring+Quartz 从数据库中获取定时任务和定时时间,动态实现对定时任务的增删改查,部署到tomcat即可看到定时任务执行效果。本人亲测,可用!
该资源描述了用spring+quartz搭建的环境来管理任务调度的基本配置
本代码是定时器的实例,两种运行模式,一种是直接以Java程序的形式运行,指定加载的配置文件;另一种是在tomcat下运行
配置Spring+quartz定时器
利用quartz动态操作定时任务,所有配置信息扔到数据库合理管理,同时把运行日志自动添加数据库表中。
spring+quartz需要的4个jar包 不需要6个 开始有人上传的6个 其实没这个必要 我来修正 一下
spring 集成quartz定时任务 用数据库实现quartz的集群
Spring+Quartz实现定时任务的配置方法.rar
主要介绍了Spring+Quartz配置定时任务实现代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
传统Spring+Quartz实现的定时器一般都是通过配置文件中配置的,这就意味着如果我们修改了定时任务的时间,就得重新启动一下Tomcat,而且每次新建一个任务就得在spring中添加相关的配置信息,非常麻烦。基于上面的...
虽然可以通过属性文件(在属性文件中可以指定 JDBC 事务的数据源、全局作业和/或触发器侦听器、插件、线程池,以及更多)配置 Quartz,但它根本没有与应用程序服务器的上下文或引用集成在一起。结果就是作业不能访问...
关于spring中quartz的配置
Spring+quartz 一个简单的 定时任务的例子,希望能对大家的学习有帮助。 最后,附:cronExpression配置说明 字段 允许值 允许的特殊字符 秒 0-59 , - * / 分 0-59 , - * / 小时 0-23 , - * / 日期 1-31 , - *...
springboot+quartz 动态化配置,可在页面操作,查看、添加、修改、删除,暂停等操作
spring3+ quartz1.8的使用开发,包括quartz在spring的各种配置,以及集群的多种版本数据库脚本,欢迎大家下载。
spring+quartz配置的定时器 可以动态添加任务
spring3.2之后quartz和之前的定时服务配置稍有不同 在这里分享一个自己写的例子(代码、源码、jar包都齐全) 直接导入myeclipse即可