posts - 11,  comments - 9,  trackbacks - 0

Quartz 配置实例

 

jobInitial.xml

<?xml version="1.0" encoding="UTF-8"?>

  <!DOCTYPE quartz PUBLIC

  "-//Quartz Enterprise Job Scheduler//DTD Job Scheduling Data 1.0//EN"

  "http://www.quartzscheduler.org/dtd/job_scheduling_data_1_0.dtd">

<quartz>

  <job>

    <job-detail>

      <name>Job1</name>

      <group>DEFAULT</group>

      <job-class>MyPackage.TestJob</job-class>

    </job-detail>

    <trigger>

      <cron>

        <name>trigger1</name>

        <group>DEFAULT</group>

        <job-name>Job1</job-name>      

        <job-group>DEFAULT</job-group>

        <cron-expression>0 0/1 * * * ?</cron-expression>

        <!-- every 1 minutes... -->

      </cron>

    </trigger>

   </job>  

   <job>

    <job-detail>

      <name>Job2</name>

      <group>DEFAULT2</group>

      <job-class>MyPackage.Job2</job-class>

    </job-detail>

    <trigger>

      <cron>

        <name>trigger2</name>

        <group>DEFAULT2</group>

        <job-name>Job2</job-name>      

        <job-group>DEFAULT2</job-group>

        <cron-expression>0 0/2 * * * ?</cron-expression>

        <!-- every 1 minutes... -->

      </cron>

    </trigger>

  </job> 

</quartz>

 

 

Quart.properties

 

# ===========================================================================

# Configure Main Scheduler Properties  ======================================

# ===========================================================================

org.quartz.scheduler.instanceName = sched1

org.quartz.scheduler.instanceId = 1

 

# ===========================================================================

# Configure ThreadPool  =====================================================

# ===========================================================================

org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool

org.quartz.threadPool.threadCount = 3

org.quartz.threadPool.threadPriority = 5

 

# ===========================================================================

# Configure JobStore  =======================================================

# ===========================================================================

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

org.quartz.jobStore.misfireThreshold = 60000

 

# ===========================================================================

# 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 = jobInitial.xml

org.quartz.plugin.jobInitializer.overWriteExistingJobs = true

org.quartz.plugin.jobInitializer.failOnFileNotFound = true

org.quartz.plugin.jobInitializer.validating = false

org.quartz.plugin.jobInitializer.validatingSchema = true

 

MAIN

public class MainClass {

   

    static Logger logger = Logger.getLogger(MainClass.class.getName());

 

    public static void main(String args[]) {

 

           SchedulerFactory schedFact = new org.quartz.impl.StdSchedulerFactory();

           Scheduler sched = null;

           try {

                  sched = schedFact.getScheduler();

                  sched.start();

                  logger.debug(">>>>> Initial Schedule Start >>>>>>>>>");

           } catch (SchedulerException e) {

                  logger.debug(">>>>> Initial Schedule Start Failed!!!", e);

                  try {

                         sched.shutdown();

                  } catch (SchedulerException e1) {

                         logger.debug(">>>>> Initial Schedule Shutdown Failed!!!", e);

                         e1.printStackTrace();

                  }

                  e.printStackTrace(System.err);

           }

    }

 

}

 

 

JOB

 

public class TestJob implements Job {

 

    public void execute(JobExecutionContext arg0) throws JobExecutionException {

           // TODO Auto-generated method stub

 

           System.out.println(" TestJob Start arg0=" + arg0);

           System.out.println(" -----------------test-----------------------");

    }

 

}

 

 

 

 

 

 

posted on 2006-03-01 22:32 square 阅读(1655) 评论(4)  编辑  收藏


FeedBack:
# re: Quartz让作业调度简单
2006-03-02 18:34 | 路过
是很方便.不过最好还是crontab吧. 有过web服务挂了,结果....  回复  更多评论
  
# re: Quartz让作业调度简单
2006-11-02 16:24 | f
fffff  回复  更多评论
  
# re: Quartz让作业调度简单
2006-11-02 16:25 | f
你的例子怎么报错啊。
org.quartz.SchedulerException: ThreadPool class 'org.quartz.simpl.SimpleThreadPool' could not be instantiated. [See nested exception: java.lang.NullPointerException]
at org.quartz.impl.StdSchedulerFactory.instantiate(StdSchedulerFactory.java:605)
at org.quartz.impl.StdSchedulerFactory.getScheduler(StdSchedulerFactory.java:1152)
at com.lp.drink.AlertTrigger.main(AlertTrigger.java:14)
* Nested Exception (Underlying Cause) ---------------
java.lang.NullPointerException
at org.quartz.simpl.LoadingLoaderClassLoadHelper.loadClass(LoadingLoaderClassLoadHelper.java:61)
at org.quartz.simpl.CascadingClassLoadHelper.loadClass(CascadingClassLoadHelper.java:118)
at org.quartz.impl.StdSchedulerFactory.instantiate(StdSchedulerFactory.java:603)
at org.quartz.impl.StdSchedulerFactory.getScheduler(StdSchedulerFactory.java:1152)
at com.lp.drink.AlertTrigger.main(AlertTrigger.java:14)
  回复  更多评论
  
# re: Quartz让作业调度简单
2006-11-05 22:27 | square[匿名]
配置文件的路径要正确

org.quartz.plugin.jobInitializer.fileName = jobInitial.xml

这里配置 job 的配置文件路径、

当然你还要注意包名
<job-class>MyPackage.TestJob</job-class>
  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航:
 
<2006年11月>
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

常用链接

留言簿(2)

随笔档案

文章档案

收藏夹

IBM developerworks JAVA

搜索

  •  

最新评论

阅读排行榜

评论排行榜