Spring之——quartz集群的问题及解决方案(基于Spring4.0+quartz2.2.1的集群架构)

特别注意一点,与Spring3.1以下版本整合必须使用Quartz1,最初我拿2.2.1的,怎么搞都报错:

Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [org.springframework.scheduling.quartz.CronTriggerBean] for bean with name 'mytrigger' defined in class path resource [applicationContext.xml]: problem with class file or dependent class; nested exception is java.lang.IncompatibleClassChangeError: class org.springframework.scheduling.quartz.CronTriggerBean has interface org.quartz.CronTrigger as super class

查看发现spring3.0.5中org.springframework.scheduling.quartz.CronTriggerBean继承了org.quartz.CronTrigger(public class CronTriggerBeanextends CronTrigger),而在quartz2.1.3中org.quartz.CronTrigger是个接口(publicabstract interface CronTrigger extends Trigger),而在quartz1.8.5及1.8.4中org.quartz.CronTrigger是个类(publicclass CronTrigger extends Trigger),从而造成无法在applicationContext中配置触发器。这是spring3.1以下版本和quartz2版本不兼容的一个bug。(感谢tiren的回复,spring3.1以及以后版本支持quartz2)

所以,我们在博文《Spring之——quartz的配置方式(集群与不集群) 》《Spring之——quartz集群(MySQL数据源)》《Spring之——quartz集群(Oracle数据源)》中,均使用的是1.x版本的quartz,那么,2.x版本的quartz如何配置呢。

那么,下面我们就基于Spring4.0+quartz2.2.1的配置来向大家介绍如何实现这样的架构。

1、创建quartz.properties文件

这个文件名称不可更改,将文件路径放置在src目录下,内容如下:

[plain]  view plain   copy
  1. #==============================================================    
  2. #Configure Main Scheduler Properties    
  3. #==============================================================     
  4. org.quartz.scheduler.instanceName = mapScheduler  
  5. org.quartz.scheduler.instanceId = AUTO  
  6.   
  7. #==============================================================    
  8. #Configure JobStore    
  9. #==============================================================   
  10. org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX  
  11. org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.StdJDBCDelegate  
  12. org.quartz.jobStore.tablePrefix = QRTZ_  
  13. org.quartz.jobStore.isClustered = true  
  14. org.quartz.jobStore.clusterCheckinInterval = 20000    
  15. org.quartz.jobStore.dataSource = myDS  
  16. org.quartz.jobStore.maxMisfiresToHandleAtATime = 1  
  17. org.quartz.jobStore.misfireThreshold = 120000  
  18. org.quartz.jobStore.txIsolationLevelSerializable = true  
  19.    
  20. #==============================================================    
  21. #Configure DataSource    
  22. #==============================================================   
  23. org.quartz.dataSource.myDS.driver = com.mysql.jdbc.Driver  
  24. org.quartz.dataSource.myDS.URL = jdbc:mysql://192.168.254.120:3306/test?useUnicode=true&characterEncoding=UTF-8  
  25. org.quartz.dataSource.myDS.user = root  
  26. org.quartz.dataSource.myDS.password = root  
  27. org.quartz.dataSource.myDS.maxConnections = 30  
  28. org.quartz.jobStore.selectWithLockSQL = SELECT * FROM {0}LOCKS WHERE LOCK_NAME = ? FOR UPDATE  
  29.   
  30. #==============================================================    
  31. #Configure ThreadPool    
  32. #==============================================================   
  33. org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool  
  34. org.quartz.threadPool.threadCount = 10  
  35. org.quartz.threadPool.threadPriority = 5  
  36. org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true  
  37.   
  38. #==============================================================  
  39. #Skip Check Update  
  40. #update:true  
  41. #not update:false  
  42. #==============================================================  
  43. org.quartz.scheduler.skipUpdateCheck = true   
  44.   
  45. #============================================================================     
  46. # Configure Plugins      
  47. #============================================================================        
  48. org.quartz.plugin.triggHistory.class = org.quartz.plugins.history.LoggingJobHistoryPlugin     
  49. org.quartz.plugin.shutdownhook.class = org.quartz.plugins.management.ShutdownHookPlugin  
  50. org.quartz.plugin.shutdownhook.cleanShutdown = true  

2.重写 quartz 的 QuartzJobBean 类
原因是在使用 quartz+spring 把 quartz 的 task 实例化进入数据库时,会产生: serializable 的错误,原因在于:

[html]  view plain   copy
  1. <bean id="jobtask" class="org.springframework.scheduling.quartz. MethodInvokingJobDetailFactoryBean ">  
  2.     <property name="targetObject">  
  3.           <ref bean="quartzJob"/>  
  4.     </property>  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值