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

          在quartz中一個作業實例必須實現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包里的這個的文件。該文件通常包含以下內容:

          #
          # 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指定作業配置文件名,下面我是為HelloworldJob 寫的一個配置,quartz_job.xml內容如下:
          <?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 有貓相伴的日子 閱讀(10405) 評論(3)  編輯  收藏 所屬分類: quartz

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

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


          網站導航:
           
          本站不再更新,歡迎光臨 java開發技術網
          主站蜘蛛池模板: 定西市| 罗平县| 彭阳县| 延寿县| 赤峰市| 璧山县| 利川市| 琼中| 通榆县| 石首市| 华宁县| 泾川县| 皋兰县| 呼和浩特市| 泌阳县| 天镇县| 东山县| 沈丘县| 瑞昌市| 丰城市| 徐汇区| 镇赉县| 麻阳| 澄迈县| 绥芬河市| 江源县| 浪卡子县| 沾化县| 酒泉市| 闽侯县| 伽师县| 池州市| 阿克苏市| 枞阳县| 日喀则市| 高雄县| 杨浦区| 阜阳市| 英山县| 资兴市| 仁怀市|