Quartz定時(shí)任務(wù)學(xué)習(xí)(二)web應(yīng)用
web中使用Quartz
1、首先在web.xml文件中加入 如下內(nèi)容(根據(jù)自己情況設(shè)定)
在web.xml中添加QuartzInitializerServlet,Quartz為能夠在web應(yīng)用中使 用,提供了一個(gè)QuartzInitializerServlet和一個(gè)QuartzInitializerListener,用于在加載web應(yīng)用時(shí), 對(duì)quartz進(jìn)行初始化。
<servlet>
<servlet-name>
QuartzInitializer
</servlet-name>
<servlet-class>
org.quartz.ee.servlet.QuartzInitializerServlet
</servlet-class>
<init-param>
<param-name>config-file</param-name>
<param-value>/quartz.properties</param-value>
</init-param>
<init-param>
<param-name>shutdown-on-unload</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
2、quartz.properties文件的配置(各項(xiàng)屬性說明下次寫),內(nèi)容如下:
上面提到了quartz.properties,這是自行指定的,Quartz提供了一個(gè)默認(rèn)的配置文件,可以滿足 基本的j2se應(yīng)用,如果在web應(yīng)用中,我們想把job,trigger配置都寫到文件中,就需要自己來寫,并指定在初始化時(shí)加載我們自己的 quratz.properties,位置放在classes下。
org.quartz.scheduler.instanceName = TestScheduler
org.quartz.scheduler.instanceId = one
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 2
org.quartz.threadPool.threadPriority = 4
org.quartz.plugin.jobInitializer.class = org.quartz.plugins.xml.JobInitializationPlugin
org.quartz.plugin.jobInitializer.fileName = quartz_job.xml
org.quartz.plugin.jobInitializer.overWriteExistingJobs = false
org.quartz.plugin.jobInitializer.failOnFileNotFound = true
org.quartz.plugin.shutdownhook.class = org.quartz.plugins.management.ShutdownHookPlugin
org.quartz.plugin.shutdownhook.cleanShutdown = true
3、 quartz_job.xml文件配置(各項(xiàng)屬性說明下次寫),內(nèi)容如下:
quartz要使用插件來加載自己的xml配置文件,上面指定加載classes"quartz_job.xml文件。
以Quartz定時(shí)任務(wù)學(xué)習(xí)(一)中的簡(jiǎn)單作業(yè)SimpleQuartzJob為例子:
<?xml version="1.0" encoding="UTF-8"?>
<quartz>
<job>
<job-detail>
<name>listener1</name>
<group>group1</group>
<job-class>SimpleQuartzJob</job-class>
</job-detail>
<trigger>
<cron>
<name>job1</name>
<group>group1</group>
<job-name>listener1</job-name>
<job-group>group1</job-group>
<cron-expression>0/10 * * * * ?</cron-expression>
</cron>
</trigger>
</job>
</quartz>
posted on 2008-07-20 01:19 百科 閱讀(582) 評(píng)論(0) 編輯 收藏