在WEB中,Quartz使用配置文件调用

两个配置文件,一个properties和一个xml

properties:

[xhtml]  view plain copy
  1. #============================================================================  
  2. # Configure Main Scheduler Properties    
  3. #============================================================================  
  4. org.quartz.scheduler.instanceName = TestScheduler  
  5. org.quartz.scheduler.instanceId = AUTO  
  6. #============================================================================  
  7. # Configure ThreadPool    
  8. #============================================================================  
  9. org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool  
  10. #处理的线程个数  
  11. org.quartz.threadPool.threadCount = 3  
  12. #线程优先级别,一般为5  
  13. org.quartz.threadPool.threadPriority = 5  
  14. #============================================================================  
  15. # Configure JobStore    
  16. #============================================================================  
  17. org.quartz.jobStore.misfireThreshold = 60000  
  18. org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore  
  19. #============================================================================  
  20. # Configure Plugins   
  21. #============================================================================  
  22. org.quartz.plugin.triggHistory.class = org.quartz.plugins.history.LoggingJobHistoryPlugin  
  23. org.quartz.plugin.jobInitializer.class = org.quartz.plugins.xml.JobInitializationPlugin  
  24. org.quartz.plugin.jobInitializer.fileNames = jobs.xml  
  25. #如果jobs.xml中存在调度器中已经有的job,true为覆盖  
  26. org.quartz.plugin.jobInitializer.overWriteExistingJobs = true  
  27. org.quartz.plugin.jobInitializer.failOnFileNotFound = true  
  28. #扫描jobs.xml的时间间隔  
  29. org.quartz.plugin.jobInitializer.scanInterval = 10000  
  30. org.quartz.plugin.jobInitializer.wrapInUserTransaction = false  

xml:

[xhtml]  view plain copy
  1. <?xml version='1.0' encoding='utf-8'?>  
  2. <quartz xmlns="http://www.opensymphony.com/quartz/JobSchedulingData"  
  3.   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.   xsi:schemaLocation="http://www.opensymphony.com/quartz/JobSchedulingData  
  5.   http://www.opensymphony.com/quartz/xml/job_scheduling_data_1_5.xsd"  
  6.   version="1.5">     
  7.   <job>        
  8.     <job-detail>        
  9.     <!-- job-detail.name不能有重复,不然会执行最后一个与之相同的job-->  
  10.      <name>ScanDirectory1</name>        
  11.      <group>DEFAULT</group>        
  12.      <description>        
  13.           A job that scans a directory for files         
  14.      </description>        
  15.      <job-class>        
  16.             com.haso.quartz.ScanDirectoryJob         
  17.      </job-class>        
  18.      <volatility>false</volatility>        
  19.      <durability>false</durability>        
  20.      <recover>false</recover>        
  21.      <job-data-map allows-transient-data="true">        
  22.          <entry>        
  23.          <key>SCAN_DIR</key>        
  24.          <value>E:/Tomcat/conf</value>        
  25.        </entry>        
  26.      </job-data-map>        
  27.     </job-detail>      
  28.       
  29.       
  30.     <trigger>  
  31.         <cron>  
  32.             <name>cron_time</name>  
  33.             <group>DEFAULT</group>  
  34.             <job-name>ScanDirectory1</job-name>  
  35.             <job-group>DEFAULT</job-group>  
  36.             <!-- 每天15点28分执行此JOB -->  
  37.             <cron-expression>0 28 15 * * ?</cron-expression>  
  38.         </cron>  
  39.     </trigger>    
  40.   </job>     
  41.   <job>        
  42.     <job-detail>        
  43.      <name>ScanDirectory2</name>        
  44.      <group>DEFAULT</group>  
  45.      <description>        
  46.           A job that scans a directory for files         
  47.      </description>        
  48.      <job-class>        
  49.             com.haso.quartz.ScanDirectoryJob         
  50.      </job-class>        
  51.      <volatility>false</volatility>        
  52.      <durability>false</durability>        
  53.      <recover>false</recover>        
  54.      <job-data-map allows-transient-data="true">        
  55.          <entry>        
  56.          <key>SCAN_DIR</key>        
  57.          <value>E:/Tomcat/conf2</value>  
  58.        </entry>        
  59.      </job-data-map>        
  60.     </job-detail>        
  61.         
  62.     <trigger>        
  63.      <simple>        
  64.        <name>scanTrigger2</name>        
  65.        <group>DEFAULT</group>        
  66.        <job-name>ScanDirectory2</job-name>        
  67.        <job-group>DEFAULT</job-group>        
  68.        <start-time>2008-09-03T14:43:00</start-time>        
  69.        <!-- repeat indefinitely every 10 seconds -->        
  70.        <repeat-count>-1</repeat-count>        
  71.        <repeat-interval>11000</repeat-interval>        
  72.      </simple>        
  73.     </trigger>        
  74.   </job>           
  75. </quartz>  

 

[java]  view plain copy
  1. package com.haso.quartz;  
  2.   
  3. import java.util.Date;  
  4.   
  5. import org.quartz.JobDetail;  
  6. import org.quartz.Scheduler;  
  7. import org.quartz.SchedulerException;  
  8. import org.quartz.Trigger;  
  9. import org.quartz.TriggerUtils;  
  10. import org.quartz.impl.StdSchedulerFactory;  
  11.   
  12. import com.haso.utils.Utils;  
  13.   
  14. public class SimpleScheduler {  
  15.         public static void main(String[] args)   
  16.         {         
  17.              SimpleScheduler simple = new SimpleScheduler();         
  18.              try  
  19.              {         
  20.                  // Create a Scheduler and schedule the Job         
  21.                  Scheduler scheduler = simple.createScheduler();         
  22. //               simple.scheduleJob(scheduler);         
  23.           
  24.                  // Start the Scheduler running         
  25.                  scheduler.start();  
  26.                  System.out.println("Scheduler started at " + Utils.dateToStr(new Date(), "yyyy-MM-dd hh:mm:ss"));  
  27.           
  28.             } catch (SchedulerException ex) {         
  29.                  ex.printStackTrace();  
  30.             }     
  31.               
  32.         }         
  33.         public Scheduler createScheduler() throws SchedulerException   
  34.         {//创建调度器         
  35.             return StdSchedulerFactory.getDefaultScheduler();  
  36.         }     
  37. }  

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值