Quartz.NET基础知识概述

Quartz.NET是什么

因为我如今使用的Quartz.NET2.2版本,相对2.x变化不大,主要是相对于1.x更新了不少东西,以下基础知识摘录网络。
Quartz.NET是一个开源的做业调度框架,是OpenSymphony 的 Quartz API的.NET移植,它用C#写成,可用于winform和asp.net应用中。它提供了巨大的灵活性而不牺牲简单性。你可以用它来
为执行一个做业而建立简单的或复杂的调度。它有不少特征,如:数据库支持,集群,插件,支持cron-like表达式等等。
Quartz.NET框架的核心是调度器。调度器负责管理Quartz.NET应用运行时环境。Quartz不单单是线程和线程管理。为确保可伸缩性,Quartz.NET采用了基于多线程的架构。启动时,框架初始
化一套worker线程,这套线程被调度器用来执行预约的做业。这就是Quartz.NET怎样能并发运行多个做业的原理。Quartz.NET依赖一套松耦合的线程池管理部件来管理线程环境。做业是一个执行任务的简单.NET类。只需实现Quartz.IJob接口,IJob接口包含惟一的一个方法Execute(),做业从这里开始执行。一旦实现了IJob接口和Execute ()方法,当Quartz.NET肯定该是做业运行的时候,它将调用做业。Execute()方法内就是要作的事情。html

Quartz.NET有以下几个特色

API 操做简单,只要几行简单的代码你就能够在应用程序里面实现本身的做业调度,并实时监视做业执行状况
触发器功能强大,比 Windows 的任务计划提供更细的触发粒度,你可使用Cron表达式来实现如每周星期一到星期五8:00am,5:00pm(工做时间)执行某一件任务
良好的可扩展性,它基于接口编程,你能够实现本身的 Schedule 调度器,Job 做业,以及 Trigger 触发器等
做业能够保存在 RAM 中,也能够持久化到数据库,支持多种数据库类型:SqlServer、Oracle、MySql等
集群,这是一个高级应用,能够在多台计算机之间建立负载平衡、容错处理
sql

Quartz.NET 2.0与之前版本的改进

2012年4月9日 Quartz.NET 2.0发布了Released版,对应于Java Quartz的2.1版本,下载地址 http://quartznet.sourceforge.net/download.html 。整个版本相对于1.0版本进行了大量的修改,单元测试的代码更友好(重构了更多的接口),API是基于泛型和.NET 3.5 SP1以后的特性,例如DateTimeOffset。这是Quartz.NET 有史以来最大的、最值得兴奋的一个版本。数据库

该版本除了在性能上有所提高外,增长了以下新特性编程

  • Scheduler.Clear() 提供方便用于清除全部任务、触发器和日程的方法
  • Scheduler.ScheduleJobs((IDictionary> triggersAndJobs, boolean replace) 方法可批量增长任务和触发器
  • Scheduler.UnscheduleJobs(IList triggerKeys) 方法提供批量取消任务
  • Scheduler.DeleteJobs(IList jobKeys) 批量删除任务
  • Scheduler.CheckExists(JobKey jobKey) 和 Scheduler.CheckExists(TriggerKey triggerKey)提供用于检测任务关键字的惟一性
  • AdoJobStore allows one set of tables to be used by multiple distinct scheduler instances
  • AdoJobStore is now capable of storing non-core Trigger implementations without using BLOB columns, through the use of the new TriggerPersistenceDelegate interface, which can (optionally) be implemented by implementers of custom Trigger types.
  • Cron 表达式支持指定每个月的最后一天和最后一周,例如 L-3 为每个月的最后三天
  • 包含调度信息的 XML 文件增长了用来指定启动时间和间隔时间的方法
  • XML 文件支持为触发器指定 priority 属性
  • 增长核心任务 DirectoryScanJob ,以前的FileScanJob 添加了一个迷你mum age参数

2.0在API上也作了重大的修改,API返回值的集合和泛型的使用,消除歧义和冗余代码,掩藏/删除不该该公开给客户端的方法,提升关注点分离,并引入 与领域特定语言DSL的核心实体(jobs and triggers),天然就有了兼容性等问题,咱们如今来看下都有哪些重大的修改:网络

  • 不在支持.NET 1.1和2.0,须要Quartz.net 2.0至少须要.NET 3.5 SP1,是因为采用了新的语言特性和类接口
  • 许多公共接口的返回值Array更改成泛型的IList和ISet,例如GetJobGroupNames(): string[] 如今更改成 GetJobGroupNames(): IList ,如今用来标识Jobs和Triggers 如今是基于JobsKey和TriggersKey,Keys 包含一个Name和一个Group。操做特定jobs/triggers 的方法使用Keys做为参数。例如GetTrigger(TriggerKey key): ITrigger 替换了GetTrigger(string name, string group): Trigger,ITrigger如今是一个接口而不是类。ISimpleTrigger, ICronTrigger也同样。新的 DSL/builder-based API 组织Jobs和Triggers。
     IJobDetail job = JobBuilder.Create<SimpleJob>() .WithIdentity("job1", "group1") .Build();
     ITrigger trigger = TriggerBuilder.Create() .WithIdentity("trigger1", "group1") .StartAt(DateBuilder.FutureDate(2, IntervalUnit.HOURS)) .WithSimpleSchedule(x => x.RepeatHourlyForever()) .ModifiedByCalendar("holidays") .Build();
  • JobInitializationPlugin 已经移除,用XMLSchedulingDataProcessorPlugin替代
  • Microsoft's Oracle drivers已经再也不支持,使用10g 或者 11g ODP.NET drivers替代
  • 数据库的Sechema已经修改,须要使用database目录下的脚本吧1.x的Schema升级到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
变化三 实现IJob接口 JobExecutionContext对象变成了IJobExecutionContext
变化四 quartz_jobs.xml配置节发生了变化
变化五 支持.Net版本不一样
    • Quartz 1.0能够支持.Net 1.1 和 .Net 2.0及以上版本 
    • Quartz 2.0仅支持.Net 3.5及以上版本,放弃了对.Net 1.1和.Net 2.0的支持

Quartz.NET 2.2 ChangeLog

This release contains important bug fixes, new functionality and minor breaking changes.
UPGRADING
Please examine and run the database\schema_20_to_22_upgrade.sql script if you are using AdoJobStore
    this script adds a new column SCHED_TIME to table QRTZ_FIRED_TRIGGERS
    file contains the alter command for SQL Server and other database samples in comments
BREAKING CHANGES
    database schema needs upgrade
    add SchedulerStarting() method to ISchedulerListener interface
    make the scheduler's TypeLoadHelper available to plugins when they are initialized
    dbFailureRetryInterval parameter was removed from DirectSchedulerFactory APIs
NEW FEATURES
    ability to override worker thread names (when using SimpleThreadPool)
    add new IScheduler method: ScheduleJob(IJobDetail job, ISet trigger) to schedule multiple triggers for a job all at once
    allow 'triggerless' initial storing of non-durable jobs.
    improvements for job recovery information
    package job_scheduling_data_2_0.xsd to nuget package's content folder
    allow scheduler exported with remoting to be used from local machine only
    support for Oracle managed ODP driver
FIXES
    job ending with exception and trigger not going to fire again, trigger is incorrectly not removed from job store
    XML schema supports multiple schedule elements but processor does not
    DailyTimeIntervalTriggerPersistenceDelegate does not handle empty time interval properly
    DailyTimeIntervalScheduleBuilder.EndingDailyAfterCount(...) doesn't pass validation
    trace throwing exception
    bug in QuartzSchedulerThread.GetRandomizedIdleWaitTime()
    can't delete or replace job without the referenced class
MISC
    Performance improvements, including improvements to some select statements in AdoJobStore
多线程

相关文章
相关标签/搜索