quartz配置

1. 开发任务类,实现Job2接口。例如:
public class BirthdayCongJob implements Job2 {
public void executeInternal() {

}

}
2. 将job bean 配置到spring-context-quartz.xml 文件中。例如:
<!-- 生日祝福quartz -->
<bean id="birthdayCongJob" class="com.thinkgem.jeesite.modules.sys.quartz.job.BirthdayCongJob"/>
<!-- 引导Job -->
<bean id="birthdayJob" class="com.thinkgem.jeesite.modules.sys.quartz.BootstrapJob">
<property name="targetJob" value="birthdayCongJob" />
</bean>

<bean id="birthdayCongJobDetail" class="com.thinkgem.jeesite.modules.sys.quartz.MethodInvokingJobDetailFactoryBean">
<property name="concurrent" value="true" />
<property name="targetObject" ref="birthdayJob" />
</bean>

<bean id="birthdayCongBean" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="birthdayCongJobDetail" />
<property name="cronExpression" value="0 0 9 * * ?" />
</bean>


3. 在spring-context-quartz.xml文件中给quartz工厂类注入CronTriggerBean(红色部分)
<!-- 配置quartz工厂类 -->
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="autoStartup" value="true"/>
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:quartz.properties" />
<property name="triggers">
<list>
<ref bean="birthdayCongBean" />
</list>
</property>
<property name="applicationContextSchedulerContextKey" value="applicationContext" />
</bean>
Quartz表说明
表名 描述
QRTZ_CALENDARS 以Blob类型存储Quartz的Calendar信息.
QRTZ_CRON_TRIGGERS 存储Cron Trigger,包括Cron表达式和时区信息.
QRTZ_FIRED_TRIGGERS 存储与已触发的Trigger相关的状态信息,以及相联Job的执行信息.
QRTZ_PAUSED_TRIGGER_GRPS 存储已暂停的Trigger组的信息。
QRTZ_SCHEDULER_STATE 存储少量的有关Scheduler的状态信息,和别的cheduler 实例(假如是用于一个集群中)
QRTZ_LOCKS 存储程序的非观锁的信息(假如使用了悲观锁)。
QRTZ_JOB_DETAILS 存储每一个已配置的Job的详细信息。
QRTZ_JOB_LISTENERS 存储有关已配置的JobListener的信息。
QRTZ_SIMPLE_TRIGGERS 存储简单的Trigger,包括重复次数,间隔,以及已触的次数。
QRTZ_BLOG_TRIGGERS Trigger作为Blob类型存储(用于Quartz用户用JDBC创建他们自己定制的Trigger类型,JobStore并不知道如何存储实例的时候)
QRTZ_TRIGGER_LISTENERS 存储已配置的TriggerListener的信息.
QRTZ_TRIGGERS 存储已配置的Trigger的信息.
QRTZ_TRIGGERS表中TRIGGER_STATE字段显示任务的属性:
WAITING:等待
PAUSED:暂停
ACQUIRED:正常执行
BLOCKED:阻塞
ERROR:错误


spring-context-quartz.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
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.2.xsd">

<!-- 生日祝福quartz -->
<bean id="birthdayCongJob" class="com.thinkgem.jeesite.modules.sys.quartz.job.BirthdayCongJob"/>
<!-- 节日问候 -->
<bean id="holidayCongJob" class="com.thinkgem.jeesite.modules.sys.quartz.job.HolidayCongJob"/>
<!-- 自动分组 -->
<bean id="customerAutoGroupJob" class="com.thinkgem.jeesite.modules.sys.quartz.job.CustomerAutoGroupJob"/>
<!-- ftp更新数据 -->
<bean id="updateDataJob" class="com.thinkgem.jeesite.modules.sys.quartz.job.UpdateDataJob"/>

<!-- 引导Job -->
<bean id="birthdayJob" class="com.thinkgem.jeesite.modules.sys.quartz.BootstrapJob">
<property name="targetJob" value="birthdayCongJob" />
</bean>

<bean id="birthdayCongJobDetail" class="com.thinkgem.jeesite.modules.sys.quartz.MethodInvokingJobDetailFactoryBean">
<property name="concurrent" value="true" />
<property name="targetObject" ref="birthdayJob" />
</bean>

<bean id="birthdayCongBean" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="birthdayCongJobDetail" />
<property name="cronExpression" value="0 0 9 * * ?" />
</bean>




<bean id="holidayJob" class="com.thinkgem.jeesite.modules.sys.quartz.BootstrapJob">
<property name="targetJob" value="holidayCongJob" />
</bean>

<bean id="holidayCongJobDetail" class="com.thinkgem.jeesite.modules.sys.quartz.MethodInvokingJobDetailFactoryBean">
<property name="concurrent" value="true" />
<property name="targetObject" ref="holidayJob" />
</bean>

<bean id="holidayCongBean" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="holidayCongJobDetail" />
<property name="cronExpression" value="0 0 9 * * ?" />
</bean>




<bean id="customerJob" class="com.thinkgem.jeesite.modules.sys.quartz.BootstrapJob">
<property name="targetJob" value="customerAutoGroupJob" />
</bean>

<bean id="customerJobDetail" class="com.thinkgem.jeesite.modules.sys.quartz.MethodInvokingJobDetailFactoryBean">
<property name="concurrent" value="true" />
<property name="targetObject" ref="customerJob" />
</bean>

<bean id="customerBean" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="customerJobDetail" />
<property name="cronExpression" value="0 0 1 * * ?" />
</bean>


<bean id="updateJob" class="com.thinkgem.jeesite.modules.sys.quartz.BootstrapJob">
<property name="targetJob" value="updateDataJob" />
</bean>

<bean id="updateJobDetail" class="com.thinkgem.jeesite.modules.sys.quartz.MethodInvokingJobDetailFactoryBean">
<property name="concurrent" value="true" />
<property name="targetObject" ref="updateJob" />
</bean>

<bean id="updateBean" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="updateJobDetail" />
<property name="cronExpression" value="0 0 1 * * ?" />
</bean>


<!-- 数据源配置,这里采用quartz 与 Spring 共用数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://172.16.128.145:3306/zhongdadb?useUnicode=true&characterEncoding=utf-8" />
<property name="username" value="zhongda" />
<property name="password" value="zhongda" />
<property name="maxActive" value="5" />
</bean>

<!-- 配置quartz工厂类 -->
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="autoStartup" value="false"/>
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:quartz.properties" />
<property name="triggers">
<list>
<ref bean="birthdayCongBean" />
<ref bean="holidayCongBean" />
<ref bean="customerBean" />
<!-- <ref bean="updateBean" /> -->
</list>
</property>
<property name="applicationContextSchedulerContextKey" value="applicationContext" />
</bean>


</beans>

quartz.properties

#============================================================================
# Configure Main Scheduler Properties
#============================================================================

org.quartz.scheduler.instanceName = TestScheduler
org.quartz.scheduler.instanceId = AUTO

#============================================================================
# Configure ThreadPool
#============================================================================

org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 10
org.quartz.threadPool.threadPriority = 5
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true

#============================================================================
# Configure JobStore
#============================================================================

org.quartz.jobStore.misfireThreshold = 60000
org.quartz.jobStore.useProperties = false

org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.useProperties=false
#org.quartz.jobStore.dataSource=myDS
org.quartz.jobStore.tablePrefix=QRTZ_
org.quartz.jobStore.isClustered=true
org.quartz.jobStore.clusterCheckinInterval=15000

#============================================================================
# Other Example Delegates
#============================================================================
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.CloudscapeDelegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.DB2v6Delegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.DB2v7Delegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.DriverDelegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.HSQLDBDelegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.MSSQLDelegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.PointbaseDelegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.WebLogicDelegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.oracle.OracleDelegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.oracle.WebLogicOracleDelegate

#============================================================================
# Configure Datasources
#============================================================================

#org.quartz.dataSource.myDS.driver=com.ibm.db2.jcc.DB2Driver
#org.quartz.dataSource.myDS.URL=jdbc:db2://172.16.113.4:50000/UUMDB
#org.quartz.dataSource.myDS.user=db2inst1
#org.quartz.dataSource.myDS.password=zone2009
#org.quartz.dataSource.myDS.maxConnections = 5
#org.quartz.dataSource.myDS.validationQuery=

#============================================================================
# Configure Plugins
#============================================================================

#org.quartz.plugin.shutdownHook.class = org.quartz.plugins.management.ShutdownHookPlugin
#org.quartz.plugin.shutdownHook.cleanShutdown = true


#org.quartz.plugin.triggHistory.class = org.quartz.plugins.history.LoggingJobHistoryPlugin
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值