Quartz(05) job 的持久化

在上一章(Quartz(04) Quartz 基本配置)中,我们在quartz.properties 文件中配置了org.quartz.jobStore.class=org.quartz.simpl.RAMJobStore , 这个配置的意思,将job运行的信息存放在内存中,Quartz也提供了另外一种持久化job运行信息的方式,存储到数据库! 比如一个任务每分钟执行一次,但是由于机器故障,服务器停止运行了一个小时,如果把job的信息存放到内存中,显然会造成信息的丢失. Quartz 便提供了一种把这些信息存储到数据的功能.

源码下载地址

Quartz 提供了两种持久化的方式,JobStoreTX和JobStoreCMT.本文以JobStoreTX讲解.在做这个功能之前,我们需要建立一套Quartz需要使用的表.这个在Quartz的文档中,针对不同数据库有不同的sql文件,选择合适的sql,在数据库中建立相应的表. 
这里写图片描述

然后我们去修改 quartz.properties文件就好了.当然jdbc的jar包少不了.quartz.properties的文件如下.

# Default Properties file for use by StdSchedulerFactory
# to create a Quartz Scheduler Instance, if a different
# properties file is not explicitly specified.
#

org.quartz.scheduler.instanceName=DefaultQuartzScheduler
org.quartz.scheduler.rmi.export=false
org.quartz.scheduler.rmi.proxy=false
org.quartz.scheduler.wrapJobExecutionInUserTransaction=false

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

#jobStoreTX TEST
org.quartz.jobStore.misfireThreshold=60000
# TX method
# jobStore 的方式为obStoreTX
org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX
#jdbc Delegate
org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate
#table prefix
org.quartz.jobStore.tablePrefix=qrtz_
#数据源的名称
org.quartz.jobStore.dataSource=myDS
#数据库连接信息,注意myDS 是和数据源同名的,上一行
org.quartz.dataSource.myDS.driver=com.mysql.jdbc.Driver   
org.quartz.dataSource.myDS.URL=jdbc:mysql://localhost:3306/test
org.quartz.dataSource.myDS.user=root   
org.quartz.dataSource.myDS.password=123456   
org.quartz.dataSource.myDS.maxConnections=10

#Configure Plugins    
#插件
org.quartz.plugin.jobInitializer.class=org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin
org.quartz.plugin.jobInitializer.fileNames=quartz_jobx.xml


  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40

这样就大功告成了.在以后我们讲到Quartz与Web/Spring的整合,并且将所有的job信息的配置到数据的表中,quartz_jobx.xml 文件就不在需要了. 
下一章节Quartz(06) quartz整合到web项目中

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值