首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

quartz日记1:基本配置

2012-10-24 
quartz日志1:基本配置好久之前用过quartz来跑定时任务,近期工作上轻松一点,回头来回味一下细节先不说,把基

quartz日志1:基本配置

好久之前用过quartz来跑定时任务,近期工作上轻松一点,回头来回味一下

细节先不说,把基本的配置先贴上来,确保可以跑出基本的服务。我没有配置spring,直接在web.xml中配置了quartz,步骤如下:

1.下载jar

老生长谈的第一步,网址http://www.terracotta.org/dl/quartz-oss-sign-up

我用的1.8.5版本,没有用最新的2.0.1版本

2.配置web.xml

? <servlet>
???? <servlet-name>quartz</servlet-name>
???? <servlet-class>
???????? org.quartz.ee.servlet.QuartzInitializerServlet
???? </servlet-class>
???? <init-param>
???????? <param-name>config-file</param-name>

<!-- 在src下新建目录configFiles用来存放各种插件的配置文件?-->
???????? <param-value>/configFiles/quartz.properties</param-value>
???? </init-param>
???? <init-param>
???????? <param-name>shutdown-on-unload</param-name>
???????? <param-value>true</param-value>
???? </init-param>
???? <init-param>
???????? <param-name>start-scheduler-on-load</param-name>
???????? <param-value>true</param-value>
???? </init-param>??
???? <load-on-startup>1</load-on-startup>
? </servlet>

3.编写quartz.properties文件

如果quartz.properties不配置的话,quartz会使用自带的一份默认配置文件

#============================================================================
# Configure Main Scheduler Properties?
#============================================================================
org.quartz.scheduler.instanceName = QuartzScheduler
org.quartz.scheduler.instanceId = AUTO
#============================================================================
# Configure ThreadPool?
#============================================================================
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 5
org.quartz.threadPool.threadPriority = 5
#============================================================================
# Configure JobStore?
#============================================================================
org.quartz.jobStore.misfireThreshold = 60000
org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
#============================================================================
# Configure Plugins
#============================================================================
#注意1.5版本之后,这个改名了。参数项也变了
#org.quartz.plugin.jobInitializer.class = org.quartz.plugins.xml.JobInitializationPlugin
org.quartz.plugin.jobInitializer.class = org.qua#rtz.plugins.xml.XMLSchedulingDataProcessorPlugin

#如果这里不指定,默认会读取WEB-INFO/CLASSES目录下的quartz_jobs.xml文件,名称不能改变

#如果有多个job xml文件,使用","隔开
org.quartz.plugin.jobInitializer.fileNames = /configFiles/quartz_jobs.xml
org.quartz.plugin.jobInitializer.failOnFileNotFound = true
org.quartz.plugin.jobInitializer.scanInterval = 60
org.quartz.plugin.jobInitializer.wrapInUserTransaction =false

4.添加quartz.jobs.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<job-scheduling-data xmlns="http://www.quartz-scheduler.org/xml/JobSchedulingData"
? xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
? xsi:schemaLocation="http://www.quartz-scheduler.org/xml/JobSchedulingData http://www.quartz-scheduler.org/xml/job_scheduling_data_1_8.xsd"
? version="1.8">

?<schedule>
??<job>
???<name>HelloWorldJob</name>
???<job-class>com.stock.finance.job.TestJob</job-class>
???<volatility>false</volatility>
???<durability>false</durability>
???<recover>false</recover>
??</job>
??<trigger>
??<simple>
???<name>helloWorldTrigger</name>
???<job-name>HelloWorldJob</job-name>
???<start-time>2011-05-17T15:53:00</start-time>
???<repeat-count>-1</repeat-count>
???<repeat-interval>30000</repeat-interval>
??</simple>
??</trigger>
?</schedule>
</job-scheduling-data>

?

热点排行