本站不再更新,欢迎光临 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 有猫相伴的日子 阅读(10371) 评论(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开发技术网