本站不再更新,歡迎光臨 java開發(fā)技術網(wǎng)
          隨筆-230  評論-230  文章-8  trackbacks-0

          在quartz中一個作業(yè)實例必須實現(xiàn)org.quartz.Job接口
          如:

          package com.unicom.gdnum.jobs;

          import java.util.*;

          import org.apache.commons.logging.*;
          import org.quartz.Job;
          import org.quartz.JobExecutionContext;
          import org.quartz.JobExecutionException;

          public class HelloworldJob implements Job{
          ?
          ?static Log log=LogFactory.getLog(HelloworldJob.class);
          ?public? HelloworldJob() {
          ??
          ?}
          ?public void execute(JobExecutionContext arg0) throws JobExecutionException {
          ??// TODO Auto-generated method stub
          ??log.info("Hello World Quartz......."+(new Date()).toLocaleString());
          ?}
          }


          quartz有自己的配置文個名為quartz.properties,如果我們不在src/(根目錄)如果我們不建立文件那么quartz就會使用quartz.jar包里的這個的文件。該文件通常包含以下內(nèi)容:

          #
          # Configure Main Scheduler Properties
          #

          org.quartz.scheduler.instanceName = TestScheduler
          org.quartz.scheduler.instanceId = AUTO

          #
          # Configure ThreadPool
          #

          org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
          org.quartz.threadPool.threadCount =? 5
          org.quartz.threadPool.threadPriority = 4

          #
          # Configure JobStore
          #

          org.quartz.jobStore.misfireThreshold = 5000

          org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore

          # ===========================================================================
          # Configure SchedulerPlugins? ===============================================
          # ===========================================================================
          org.quartz.plugin.triggHistory.class = org.quartz.plugins.history.LoggingTriggerHistoryPlugin
          org.quartz.plugin.triggHistory.triggerFiredMessage = Trigger {1}.{0} fired job {6}.{5} at: {4, date, HH:mm:ss MM/dd/yyyy}
          org.quartz.plugin.triggHistory.triggerCompleteMessage = Trigger {1}.{0} completed firing job {6}.{5} at {4, date, HH:mm:ss MM/dd/yyyy} with resulting trigger instruction code: {9}

          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

          以上配置quartz所需的配置,其中org.quartz.plugin.jobInitializer.fileName = /quartz_job.xml指定作業(yè)配置文件名,下面我是為HelloworldJob 寫的一個配置,quartz_job.xml內(nèi)容如下:
          <?xml version="1.0" encoding="UTF-8"?>
          <quartz>
          ? <job>
          ??? <job-detail>
          ????? <name>helloworld</name>
          ????? <group>group1</group>
          ????? <job-class>com.unicom.gdnum.jobs.HelloworldJob</job-class>
          ??? </job-detail>
          ??? <trigger>
          ????? <cron>
          ??????? <name>test</name>
          ??????? <group>group1</group>
          ??????? <job-name>helloworld</job-name>
          ??????? <job-group>group1</job-group>
          ??????? <cron-expression>0 0/1 * * * ?</cron-expression>
          ???? </cron>
          ??? </trigger>
          ? </job>
          </quartz>

          這是在tomcat中作的一個例子,當然要使用quartz面要下載其相關包!

          posted on 2006-07-18 14:38 有貓相伴的日子 閱讀(10402) 評論(3)  編輯  收藏 所屬分類: quartz

          評論:
          # re: 一個非常簡單的quartz例子[未登錄] 2007-09-27 17:53 |
          請問如果我要配置多個作業(yè),配置文件應該怎樣寫呢?  回復  更多評論
            
          # re: 一個非常簡單的quartz例子[未登錄] 2008-04-18 17:09 | CoderDream
          難道不需要在web.xml中配置?  回復  更多評論
            
          # re: 一個非常簡單的quartz例子 2009-11-22 14:14 | phh
          @宇
          xml里配多個Job。。。  回復  更多評論
            

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導航:
           
          本站不再更新,歡迎光臨 java開發(fā)技術網(wǎng)
          主站蜘蛛池模板: 株洲县| 琼结县| 石景山区| 文昌市| 牟定县| 信宜市| 南宫市| 崇义县| 台南县| 安新县| 保亭| 通榆县| 高清| 车险| 丁青县| 壤塘县| 屯留县| 越西县| 庆云县| 云和县| 英吉沙县| 夹江县| 望都县| 子长县| 梅河口市| 峨边| 华安县| 井研县| 札达县| 榆社县| 扬中市| 镇雄县| 油尖旺区| 介休市| 石狮市| 偃师市| 武汉市| 措勤县| 宜良县| 来凤县| 竹山县|