Quartz(05) job 的持久化

来源:互联网 发布:linux操作系统课件 编辑:程序博客网 时间:2024/06/07 05:53

在上一章中,我们在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=DefaultQuartzSchedulerorg.quartz.scheduler.rmi.export=falseorg.quartz.scheduler.rmi.proxy=falseorg.quartz.scheduler.wrapJobExecutionInUserTransaction=falseorg.quartz.threadPool.class=org.quartz.simpl.SimpleThreadPoolorg.quartz.threadPool.threadCount=10org.quartz.threadPool.threadPriority=5org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread=true#jobStoreTX TESTorg.quartz.jobStore.misfireThreshold=60000# TX method# jobStore 的方式为obStoreTXorg.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX#jdbc Delegateorg.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate#table prefixorg.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/testorg.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.XMLSchedulingDataProcessorPluginorg.quartz.plugin.jobInitializer.fileNames=quartz_jobx.xml

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

0 0
原创粉丝点击