Quartz 在开源任务调度框架中的翘首,它提供了强大任务调度机制,难能可贵的是它同时保持了使用的简单性。
Quartz 允许开发人员灵活地定义触发器的调度时间表,并可以对触发器和任务进行关联映射。
Spring为创建Quartz的Scheduler、Trigger和JobDetail提供了便利的FactoryBean类,以便能够在Spring 容器中享受注入的好处。
此外Spring还提供了一些便利工具类直接将Spring中的Bean包装成合法的任务。
Spring进一步降低了使用Quartz的难度,能以更具Spring风格的方式使用Quartz。
概括来说它提供了两方面的支持:
1)为Quartz的重要组件类提供更具Bean风格的扩展类;
2)提供创建Scheduler的BeanFactory类,方便在Spring环境下创建对应的组件对象,并结合Spring容器生命周期进行启动和停止的动作。
注意:项目中需要加载需要加入spring.jar quartz-all-1.6.0.jar log4j-1.2.14.jar commons-collections.jar jta.jar commons-logging.jar这几个包
配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<!--
DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN"
"http://www.springframework.org/dtd/spring-beans-2.0.dtd"
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd ">
<bean id="JobProcessBeanId" class="xxx.xxxxx.xx.xx.xxxxx.JobProcessService">
<property name="jdbcTmp" ref="jdbcTmp"></property>
</bean>
<bean id="XXXXXXReflushJob_onstart" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject">
<ref bean="JobProcessBeanId" />
</property>
<property name="targetMethod">
<value>doProcess</value>
</property>
</bean>
<bean id="doProcessTime" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="XXXXXXReflushJob_onstart" />
</property>
<!-- cron表达式 -->
<property name="cronExpression">
<value>0 * * * * ?</value>
</property>
</bean>
<!-- 总管理类 如果将lazy-init='false'那么容器启动就会执行调度程序 -->
<bean id="startQuertz" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="doProcessTime" />
</list>
</property>
</bean>
</beans>
public class JobProcessService{
public void doProcess(){
System.out.println("处理业务");
}
}
分享到:
相关推荐
Spring中的Quartz配置-Spring-定时器-java定时器.doc
Quartz定时器。Spring中Quartz的配置
关于spring中quartz的配置
Spring Quartz如何动态配置时间
spring-quartz的标准配置文件
Spring中Quartz详细配置实例+所用包(spring.jar quartz-all-1.6.0.jar log4j-1.2.14.jar commons-collections.jar jta.jar commons-logging.jar)
spring3 配置quartz定时任务的使用。一个小例子。可直接运行Test.java。就可以启动定时任务。每10秒钟执行一次,可以根据自己配置。
java + quartz实现定时任务,实现集群配置,在集群环境下多节点运行定时Quartz定任务,就会存在重复处理任务的现象,为解决这一问题,下面我将介绍使用 Quartz 的 TASK ( 12 张表)实例化到数据库,基于数据库自动...
在实际项目应用中经常会用到定时任务,可以通过quartz和spring的简单配置即可完成,但如果要改变任务的执行时间、频率,废弃任务等就需要改变配置甚至代码需要重启服务器,这里介绍一下如何通过quartz与spring的组合...
NULL 博文链接:https://xpninja.iteye.com/blog/1138916
针对于spring集成quartz配置进行详细说明,并提供部分简单示例说明配置。
Spring中Quartz的配置[总结].pdf
定时任务demo,Java语言,spring整合quartz配置文件实现定时任务
NULL 博文链接:https://vista-move.iteye.com/blog/2274246
Quartz2.2.1基于Spring注解方式配置QuartzL,具体过程的效果看博文 http://blog.csdn.net/evankaka/article/details/45400781
此资源为配置文件示例,Spring集成quartz的配置。
spring 在配置quartz定时任务时所需要的jar包,里面含有两个包quartz-all-1.8.3和commons-logging-1.0.4
spring 集成quartz定时任务 用数据库实现quartz的集群
spring多个定时任务quartz配置