概述
最近项目中用到quartz集群,下面记录一下配置步骤及注意事项
1.需要的相关包这里就不说了,需要注意的是集群需要在数据库里新建相关的表,建表语句在quartz包里的quartz-1.6.5docsdbTables路径下
找到后直接在数据库中运行就可以了
2.在src下新建quartz.properties,相关参数默认的就好,不需要改
##Quartz u8C03u5EA6u4EFBu52A1u6240u9700u7684u914Du7F6Eu6587u4EF6
##org.quartz.scheduler.instanceNameu5C5Eu6027u53EFu4E3Au4EFBu4F55u503CuFF0Cu7528u5728 JDBC JobStore u4E2Du6765u552Fu4E00u6807u8BC6u5B9Eu4F8BuFF0Cu4F46u662Fu6240u6709u96C6u7FA4u8282u70B9u4E2Du5FC5u987Bu76F8u540Cu3002
org.quartz.scheduler.instanceName = HumsScheduler
##org.quartz.scheduler.instanceIdu3000u5C5Eu6027u4E3A AUTOu5373u53EFuFF0Cu57FAu4E8Eu4E3Bu673Au540Du548Cu65F6u95F4u6233u6765u4EA7u751Fu5B9Eu4F8B IDu3002
org.quartz.scheduler.instanceId = AUTO
orgorg.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 10
org.quartz.threadPool.threadPriority = 5
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true
org.quartz.jobStore.misfireThreshold = 60000
##org.quartz.jobStore.classu5C5Eu6027u4E3A JobStoreTXuFF0Cu5C06u4EFBu52A1u6301u4E45u5316u5230u6570u636Eu4E2Du3002
##u56E0u4E3Au96C6u7FA4u4E2Du8282u70B9u4F9Du8D56u4E8Eu6570u636Eu5E93u6765u4F20u64AD Scheduler u5B9Eu4F8Bu7684u72B6u6001uFF0Cu4F60u53EAu80FDu5728u4F7Fu7528 JDBC JobStore u65F6u5E94u7528 Quartz u96C6u7FA4u3002
##u8FD9u610Fu5473u7740u4F60u5FC5u987Bu4F7Fu7528 JobStoreTX u6216u662F JobStoreCMT u4F5Cu4E3A Job u5B58u50A8uFF1Bu4F60u4E0Du80FDu5728u96C6u7FA4u4E2Du4F7Fu7528 RAMJobStoreu3002
orgorg.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
orgorg.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.tablePrefix = QRTZ_
org.quartz.jobStore.maxMisfiresToHandleAtATime=10
##org.quartz.jobStore.isClustered u5C5Eu6027u4E3A trueuFF0Cu4F60u5C31u544Au8BC9u4E86 Scheduler u5B9Eu4F8Bu8981u5B83u53C2u4E0Eu5230u4E00u4E2Au96C6u7FA4u5F53u4E2Du3002
##u8FD9u4E00u5C5Eu6027u4F1Au8D2Fu7A7Fu4E8Eu8C03u5EA6u6846u67B6u7684u59CBu7EC8uFF0Cu7528u4E8Eu4FEEu6539u96C6u7FA4u73AFu5883u4E2Du64CDu4F5Cu7684u9ED8u8BA4u884Cu4E3Au3002
org.quartz.jobStore.isClustered = true
##org.quartz.jobStore.clusterCheckinInterval u5C5Eu6027u5B9Au4E49u4E86Scheduler u5B9Eu4F8Bu68C0u5165u5230u6570u636Eu5E93u4E2Du7684u9891u7387(u5355u4F4DuFF1Au6BEBu79D2)u3002
##Scheduler u68C0u67E5u662Fu5426u5176u4ED6u7684u5B9Eu4F8Bu5230u4E86u5B83u4EECu5E94u5F53u68C0u5165u7684u65F6u5019u672Au68C0u5165uFF1Bu8FD9u80FDu6307u51FAu4E00u4E2Au5931u8D25u7684 Scheduler u5B9Eu4F8BuFF0Cu4E14u5F53u524D Scheduler u4F1Au4EE5u6B64u6765u63A5u7BA1u4EFBu4F55u6267u884Cu5931u8D25u5E76u53EFu6062u590Du7684 Jobu3002
##u901Au8FC7u68C0u5165u64CDu4F5CuFF0CScheduler u4E5Fu4F1Au66F4u65B0u81EAu8EABu7684u72B6u6001u8BB0u5F55u3002clusterChedkinInterval u8D8Au5C0FuFF0CScheduler u8282u70B9u68C0u67E5u5931u8D25u7684 Scheduler u5B9Eu4F8Bu5C31u8D8Au9891u7E41u3002u9ED8u8BA4u503Cu662F 15000 (u537315 u79D2)u3002
org.quartz.jobStore.clusterCheckinInterval =20000
3.在spring配置文件中添加定时任务
<bean id="autoEtdzJob" class=" com.atoz.action.order.DealToCouponQuartz"></bean>
<bean name="quartzScheduler"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="applicationContextSchedulerContextKey" value="applicationContextKey" />
<property name="configLocation" value="classpath:quartz.properties" />
<property name="triggers">
<list>
<ref bean="trigger1" />
</list>
</property>
</bean>
<bean id="jobDetail1"
class="frameworkx.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="autoEtdzJob" />
<property name="targetMethod" value="tocouponStatusTimer" />
<property name="shouldRecover" value="true" />
</bean>
<bean id="trigger1" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="jobDetail1" />
<property name="cronExpression" value="0 0/1 * * * ?" />
</bean>
注意:如果直接用spring的MethodInvokingJobDetailFactoryBean会报序列化错误,所以需要重写MethodInvokingJobDetailFactoryBean,我当时添加后依然报序列化错误,还需要在定时任务的java类里也实现序列化,如我的定时任务类是DealToCouponQuartz,则
public class DealToCouponQuartz implements Serializable {
private transient TeamPnrMapper teamPnrMapper;
}
最后
以上就是俏皮砖头为你收集整理的quartz集群的全部内容,希望文章能够帮你解决quartz集群所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复