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

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
    # You can configure your scheduler in either <quartz> configuration section
    # or in quartz properties file
    # Configuration section has precedence
    
    quartz.scheduler.instanceName = ServerScheduler
    
    # configure thread pool info
    quartz.threadPool.type = Quartz.Simpl.SimpleThreadPool, Quartz
    quartz.threadPool.threadCount = 10
    quartz.threadPool.threadPriority = Normal
    
    # job initialization plugin handles our xml reading, without it defaults are used -->
    quartz.plugin.xml.type = Quartz.Plugin.Xml.JobInitializationPlugin, Quartz
    quartz.plugin.xml.fileNames = ~/quartz_jobs.xml
    
    # export this server to remoting context
    quartz.scheduler.exporter.type = Quartz.Simpl.RemotingSchedulerExporter, Quartz
    quartz.scheduler.exporter.port = 555
    quartz.scheduler.exporter.bindName = QuartzScheduler
    quartz.scheduler.exporter.channelType = tcp
  •  2.0 quartz.config
    # You can configure your scheduler in either <quartz> configuration section
    # or in quartz properties file
    # Configuration section has precedence
    
    quartz.scheduler.instanceName = ServerScheduler
    
    # configure thread pool info
    quartz.threadPool.type = Quartz.Simpl.SimpleThreadPool, Quartz
    quartz.threadPool.threadCount = 10
    quartz.threadPool.threadPriority = Normal
    
    # job initialization plugin handles our xml reading, without it defaults are used
    quartz.plugin.xml.type = Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin, Quartz
    quartz.plugin.xml.fileNames = ~/quartz_jobs.xml
    
    # export this server to remoting context
    quartz.scheduler.exporter.type = Quartz.Simpl.RemotingSchedulerExporter, Quartz
    quartz.scheduler.exporter.port = 555
    quartz.scheduler.exporter.bindName = QuartzScheduler
    quartz.scheduler.exporter.channelType = tcp
    quartz.scheduler.exporter.channelName = httpQuartz

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

  • 1.0 IJob接口 
    public class SimpleJob : IJob
        {
            #region IJob 成员
    
            public void Execute(JobExecutionContext context)
            {
                throw new NotImplementedException();
            }
    
            #endregion
        }

  • 2.0 IJob接口
    public class SimpleJob : IJob
        {
            #region IJob 成员
    
            public void Execute(IJobExecutionContext context)
            {
                throw new NotImplementedException();
            }
    
            #endregion
        }

 

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

  • 根结点有<quartz>变为了<job-scheduling-data>
  • 新增了<schedule>节点,<job>均放在<schedule>节点下,删除了 <job-detail>节点,同时删除了<volatile>false</volatile>属性
  • <trigger>不在放置在<job>下面,改为和<job>平行
  • 1.0 quartz_jobs.xml示例
    <?xml version="1.0" encoding="UTF-8"?>
    <quartz xmlns="http://quartznet.sourceforge.net/JobSchedulingData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0" overwrite-existing-jobs="true">
    
      <job>
        <job-detail>
          <name>sampleJob</name>
          <group>sampleGroup</group>
          <description>Sample job for Quartz Server</description>
          <job-type>Quartz.Job.NoOpJob, Quartz</job-type>
          <volatile>false</volatile>
          <durable>true</durable>
          <recover>false</recover>
        </job-detail>  
        <trigger>
          <simple>
            <name>sampleSimpleTrigger</name>
            <group>sampleSimpleGroup</group>
            <description>Simple trigger to simply fire sample job</description>
            <misfire-instruction>SmartPolicy</misfire-instruction>
            <volatile>false</volatile>
            <job-name>sampleJob</job-name>
            <job-group>sampleGroup</job-group>
            <repeat-count>RepeatIndefinitely</repeat-count>
            <repeat-interval>3000</repeat-interval>
          </simple>
        </trigger>
      </job>
    
      <job>
        <job-detail>
          <name>sampleJob2</name>
          <group>sampleGroup2</group>
          <description>Sample job for Quartz Server</description>
          <job-type>Quartz.Job.NoOpJob, Quartz</job-type>
          <volatile>false</volatile>
          <durable>true</durable>
          <recover>false</recover>
        </job-detail>  
        <trigger>
          <cron>
            <name>sampleSimpleTrigger2</name>
            <group>sampleSimpleTrigger2</group>
            <job-name>sampleJob2</job-name>
            <job-group>sampleGroup2</job-group>
            <cron-expression>0/10 * * * * ?</cron-expression>
          </cron>
        </trigger>
      </job>
    </quartz>

  • 2.0 quartz_jobs.xml示例
    <?xml version="1.0" encoding="UTF-8"?>
    
    <!-- This file contains job definitions in schema version 2.0 format -->
    
    <job-scheduling-data xmlns="http://quartznet.sourceforge.net/JobSchedulingData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0">
    
      <processing-directives>
        <overwrite-existing-data>true</overwrite-existing-data>
      </processing-directives>
    
      <schedule>
    
        <job>
            <name>sampleJob</name>
            <group>sampleGroup</group>
            <description>Sample job for Quartz Server</description>
            <job-type>Quartz.Server.SampleJob, Quartz.Server</job-type>
            <durable>true</durable>
            <recover>false</recover>
        </job>
        <trigger>
          <simple>
            <name>sampleSimpleTrigger</name>
            <group>sampleSimpleGroup</group>
            <description>Simple trigger to simply fire sample job</description>
            <job-name>sampleJob</job-name>
            <job-group>sampleGroup</job-group>
            <misfire-instruction>SmartPolicy</misfire-instruction>
            <repeat-count>-1</repeat-count>
            <repeat-interval>10000</repeat-interval>
          </simple>
        </trigger>
    
        <job>
          <name>CommissionJob</name>
          <group>CommissionJob</group>
          <description>Sample job for Quartz Server</description>
          <job-type>Settlement.Jobs.CommissionJob, Settlement.Jobs</job-type>
          <durable>true</durable>
          <recover>false</recover>
        </job>
         <trigger>
          <cron>
            <name>sampleSimpleTrigger2</name>
            <group>sampleSimpleTrigger2</group>
            <job-name>sampleJob2</job-name>
            <job-group>sampleGroup2</job-group>
            <cron-expression>0/10 * * * * ?</cron-expression>
          </cron>
        </trigger>
      </schedule>
    </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的支持

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值