Quartz.NET 2.0 2012年4月9日发布了Released

Quartz.NET 项目地址 http://quartznet.sourceforge.net/

Quartz.NET 2.0 学习笔记(1) :Quartz.NET简介

Quartz.NET 2.0 学习笔记(2) :和1.0的几点不同

Quartz.NET 2.0 学习笔记(3) :通过配置文件实现任务调度

Quartz.NET 2.0 学习笔记(4) :cron表达式

Quartz.NET 2.0 学习笔记(5) :实例创建Windows服务实现任务调度

日常开发来说,相对于1.0版,2.0版在使用上有以下几点需要注意的变化

变化一 比1.0多引用了C5.dll

  • C5.dll 一个C#和其他CLI语言的泛型集合类。.Net2.0及以上才可以使用。简介地址:http://www.itu.dk/research/c5/

变化二 quartz.config有细微变化

  • quartz.plugin.xml.type由1.x的Quartz.Plugin.Xml.JobInitializationPlugin, Quartz变为了2.0中的Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin, Quartz
  • 2.0版本新增了一行配置quartz.scheduler.exporter.channelName = httpQuart
  • 1.0 quartz.config
    1. # You can configure your scheduler in either <quartz> configuration section  
    2. # or in quartz properties file  
    3. # Configuration section has precedence  
    4.   
    5. quartz.scheduler.instanceName = ServerScheduler  
    6.   
    7. # configure thread pool info  
    8. quartz.threadPool.type = Quartz.Simpl.SimpleThreadPool, Quartz  
    9. quartz.threadPool.threadCount = 10  
    10. quartz.threadPool.threadPriority = Normal  
    11.   
    12. # job initialization plugin handles our xml reading, without it defaults are used -->  
    13. quartz.plugin.xml.type = Quartz.Plugin.Xml.JobInitializationPlugin, Quartz  
    14. quartz.plugin.xml.fileNames = ~/quartz_jobs.xml  
    15.   
    16. # export this server to remoting context  
    17. quartz.scheduler.exporter.type = Quartz.Simpl.RemotingSchedulerExporter, Quartz  
    18. quartz.scheduler.exporter.port = 555  
    19. quartz.scheduler.exporter.bindName = QuartzScheduler  
    20. quartz.scheduler.exporter.channelType = tcp  
  •  2.0 quartz.config
    1. # You can configure your scheduler in either <quartz> configuration section  
    2. # or in quartz properties file  
    3. # Configuration section has precedence  
    4.   
    5. quartz.scheduler.instanceName = ServerScheduler  
    6.   
    7. # configure thread pool info  
    8. quartz.threadPool.type = Quartz.Simpl.SimpleThreadPool, Quartz  
    9. quartz.threadPool.threadCount = 10  
    10. quartz.threadPool.threadPriority = Normal  
    11.   
    12. # job initialization plugin handles our xml reading, without it defaults are used  
    13. quartz.plugin.xml.type = Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin, Quartz  
    14. quartz.plugin.xml.fileNames = ~/quartz_jobs.xml  
    15.   
    16. # export this server to remoting context  
    17. quartz.scheduler.exporter.type = Quartz.Simpl.RemotingSchedulerExporter, Quartz  
    18. quartz.scheduler.exporter.port = 555  
    19. quartz.scheduler.exporter.bindName = QuartzScheduler  
    20. quartz.scheduler.exporter.channelType = tcp  
    21. quartz.scheduler.exporter.channelName = httpQuartz  

变化三 实现IJob接口 JobExecutionContext对象变成了IJobExecutionContext 

  • 1.0 IJob接口 
    1. public class SimpleJob : IJob  
    2.     {  
    3.         #region IJob 成员  
    4.   
    5.         public void Execute(JobExecutionContext context)  
    6.         {  
    7.             throw new NotImplementedException();  
    8.         }  
    9.  
    10.         #endregion  
    11.     }  

  • 2.0 IJob接口
    1. public class SimpleJob : IJob  
    2.     {  
    3.         #region IJob 成员  
    4.   
    5.         public void Execute(IJobExecutionContext context)  
    6.         {  
    7.             throw new NotImplementedException();  
    8.         }  
    9.  
    10.         #endregion  
    11.     }  

 

变化四 quartz_jobs.xml配置节发生了变化

  • 根结点有<quartz>变为了<job-scheduling-data>
  • 新增了<schedule>节点,<job>均放在<schedule>节点下,删除了 <job-detail>节点,同时删除了<volatile>false</volatile>属性
  • <trigger>不在放置在<job>下面,改为和<job>平行
  • 1.0 quartz_jobs.xml示例
    1. <?xml version="1.0" encoding="UTF-8"?>  
    2. <quartz xmlns="http://quartznet.sourceforge.net/JobSchedulingData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0" overwrite-existing-jobs="true">  
    3.   
    4.   <job>  
    5.     <job-detail>  
    6.       <name>sampleJob</name>  
    7.       <group>sampleGroup</group>  
    8.       <description>Sample job for Quartz Server</description>  
    9.       <job-type>Quartz.Job.NoOpJob, Quartz</job-type>  
    10.       <volatile>false</volatile>  
    11.       <durable>true</durable>  
    12.       <recover>false</recover>  
    13.     </job-detail>    
    14.     <trigger>  
    15.       <simple>  
    16.         <name>sampleSimpleTrigger</name>  
    17.         <group>sampleSimpleGroup</group>  
    18.         <description>Simple trigger to simply fire sample job</description>  
    19.         <misfire-instruction>SmartPolicy</misfire-instruction>  
    20.         <volatile>false</volatile>  
    21.         <job-name>sampleJob</job-name>  
    22.         <job-group>sampleGroup</job-group>  
    23.         <repeat-count>RepeatIndefinitely</repeat-count>  
    24.         <repeat-interval>3000</repeat-interval>  
    25.       </simple>  
    26.     </trigger>  
    27.   </job>  
    28.   
    29.   <job>  
    30.     <job-detail>  
    31.       <name>sampleJob2</name>  
    32.       <group>sampleGroup2</group>  
    33.       <description>Sample job for Quartz Server</description>  
    34.       <job-type>Quartz.Job.NoOpJob, Quartz</job-type>  
    35.       <volatile>false</volatile>  
    36.       <durable>true</durable>  
    37.       <recover>false</recover>  
    38.     </job-detail>    
    39.     <trigger>  
    40.       <cron>  
    41.         <name>sampleSimpleTrigger2</name>  
    42.         <group>sampleSimpleTrigger2</group>  
    43.         <job-name>sampleJob2</job-name>  
    44.         <job-group>sampleGroup2</job-group>  
    45.         <cron-expression>0/10 * * * * ?</cron-expression>  
    46.       </cron>  
    47.     </trigger>  
    48.   </job>  
    49. </quartz>  

  • 2.0 quartz_jobs.xml示例
    1. <?xml version="1.0" encoding="UTF-8"?>  
    2.   
    3. <!-- This file contains job definitions in schema version 2.0 format -->  
    4.   
    5. <job-scheduling-data xmlns="http://quartznet.sourceforge.net/JobSchedulingData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0">  
    6.   
    7.   <processing-directives>  
    8.     <overwrite-existing-data>true</overwrite-existing-data>  
    9.   </processing-directives>  
    10.   
    11.   <schedule>  
    12.   
    13.     <job>  
    14.         <name>sampleJob</name>  
    15.         <group>sampleGroup</group>  
    16.         <description>Sample job for Quartz Server</description>  
    17.         <job-type>Quartz.Server.SampleJob, Quartz.Server</job-type>  
    18.         <durable>true</durable>  
    19.         <recover>false</recover>  
    20.     </job>  
    21.     <trigger>  
    22.       <simple>  
    23.         <name>sampleSimpleTrigger</name>  
    24.         <group>sampleSimpleGroup</group>  
    25.         <description>Simple trigger to simply fire sample job</description>  
    26.         <job-name>sampleJob</job-name>  
    27.         <job-group>sampleGroup</job-group>  
    28.         <misfire-instruction>SmartPolicy</misfire-instruction>  
    29.         <repeat-count>-1</repeat-count>  
    30.         <repeat-interval>10000</repeat-interval>  
    31.       </simple>  
    32.     </trigger>  
    33.   
    34.     <job>  
    35.       <name>CommissionJob</name>  
    36.       <group>CommissionJob</group>  
    37.       <description>Sample job for Quartz Server</description>  
    38.       <job-type>Settlement.Jobs.CommissionJob, Settlement.Jobs</job-type>  
    39.       <durable>true</durable>  
    40.       <recover>false</recover>  
    41.     </job>  
    42.      <trigger>  
    43.       <cron>  
    44.         <name>sampleSimpleTrigger2</name>  
    45.         <group>sampleSimpleTrigger2</group>  
    46.         <job-name>sampleJob2</job-name>  
    47.         <job-group>sampleGroup2</job-group>  
    48.         <cron-expression>0/10 * * * * ?</cron-expression>  
    49.       </cron>  
    50.     </trigger>  
    51.   </schedule>  
    52. </job-scheduling-data>  


 变化五 支持.Net版本不同

  • Quartz 1.0可以支持.Net 1.1 和 .Net 2.0及以上版本 
  • Quartz 2.0仅支持.Net 3.5及以上版本,放弃了对.Net 1.1和.Net 2.0的支持