对于SimpleTrigger你需要知道它的启动总是在一个特殊的时间点或者有你设置的重复时间段中。直白来说,如果你想在2005年1月13日,正好上午11时23分54秒触发,然后执行五次,每十秒钟。

从这个描述中你并没有发现什么特别的内容对于SimpleTrigger:开启时间,结束时间、重复次数、重复时间段。对于这些你期望的内容,仅用两个注意来说明。

这个重复的次数可以是0、任意正整数、常数。SimpleTrigger. RepeatIndefinitely(无限重复)。这重复间隔属性值必须是TimeSpan.Zero或者正 TimeSpan值。注意重复间隔为0的时候导致并发触发(可能接近管理器可管理的极限)。

如果您还不熟悉DateTime类,你会发现它对于你计算触发时间很有帮助,依赖于你想创建时UTC时间(或结束时间UTC)。

EndTimeUtc 属性会限制你的重复次数。对于你不想计算起止时间之间时间片数量,而只执行没十秒一次以及结束时间。

TriggerBuilder 来创建SimpleTrigger 实例并能操作主要属性使用WithSimpleSchedule 扩展方法去设置属性值。

构建一个trigger 在一个时间点,不重复执行:

 // trigger builder creates simple trigger by default, actually an ITrigger is returned
ISimpleTrigger trigger = (ISimpleTrigger) TriggerBuilder.Create()
.WithIdentity("trigger1", "group1")
.StartAt(myStartTime) // some Date
.ForJob("job1", "group1") // identify job with name, group strings
.Build()

构建一个Trigger在一个时间点,每十秒执行一次,重复十次:

 trigger = TriggerBuilder.Create()
.WithIdentity("trigger3", "group1")
.StartAt(myTimeToStartFiring) // if a start time is not given (if this line were omitted), "now" is implied
.WithSimpleSchedule(x => x
.WithIntervalInSeconds()
.WithRepeatCount()) // note that 10 repeats will give a total of 11 firings
.ForJob(myJob) // identify job with handle to its JobDetail itself
.Build();

构建一个Trigger只执行一次,为五分钟以后启动

 trigger = (ISimpleTrigger) TriggerBuilder.Create()
.WithIdentity("trigger5", "group1")
.StartAt(DateBuilder.FutureDate(, IntervalUnit.Minute)) // use DateBuilder to create a date in the future
.ForJob(myJobKey) // identify job with its JobKey
.Build();

构建一个Trigger每五分钟执行一次一直执行22:00

 trigger = TriggerBuilder.Create()
.WithIdentity("trigger7", "group1")
.WithSimpleSchedule(x => x
.WithIntervalInMinutes()
.RepeatForever())
.EndAt(DateBuilder.DateOf(, , ))
.Build();

构建一个Trigger一小时后启动,每两小时重复一次,一直执行

 trigger = TriggerBuilder.Create()
.WithIdentity("trigger8") // because group is not specified, "trigger8" will be in the default group
.StartAt(DateBuilder.EvenHourDate(null)) // get the next even-hour (minutes and seconds zero ("00:00"))
.WithSimpleSchedule(x => x
.WithIntervalInHours()
.RepeatForever())
// note that in this example, 'forJob(..)' is not called
// - which is valid if the trigger is passed to the scheduler along with the job
.Build();

10 await scheduler.scheduleJob(trigger, job);

所有的Trigger使用TriggerBuilder简洁的语言来书写,并使用了WithSimpleSchedule方法,让你能知道怎样选择构建参数,这些都在例子中给出。

SimpleTrigger Misfire Instructions

SimpleTrigge也有一些指令信息能在在Quartz执行当misfire发生的时候(misfire详细内容请参见相应的章节)。 这些指令定义在MisfirePolicy.SimpleTrigge作为常量(在API文档中有详细的描述)。包括以下:

  • MisfireInstruction.IgnoreMisfirePolicy
  • MisfirePolicy.SimpleTrigger.FireNow
  • MisfirePolicy.SimpleTrigger.RescheduleNowWithExistingRepeatCount
  • MisfirePolicy.SimpleTrigger.RescheduleNowWithRemainingRepeatCount
  • MisfirePolicy.SimpleTrigger.RescheduleNextWithRemainingCount
  • MisfirePolicy.SimpleTrigger.RescheduleNextWithExistingCount

你可以从早期的课程中去了解 MisfirePolicy.SmartPolicy 的使用,并且这些指令为所有的Trigger所使用。

它是非常简单的使用起来。SimpleTrigger 可以动态的选择在MISFIRE 指令根据配置信息以及状态信息。关于SimpleTrigger.UpdateAfterMisfire()文档中已经解释了其执行的细节。

当你正在构建SimpleTriggers时候,你可以指定MisFire指令作为schedule 一部分:

 trigger = TriggerBuilder.Create()
.WithIdentity("trigger7", "group1")
.WithSimpleSchedule(x => x
.WithIntervalInMinutes()
.RepeatForever()
.WithMisfireHandlingInstructionNextWithExistingCount())
.Build()

Quartz 第五课 SimpleTriggers 官方文档翻译的更多相关文章

  1. [译]Quartz.NET 框架 教程(中文版)2.2.x 之第五课 SimpleTrigger

    第五课 SimpleTrigger 如果你需要在一个指定时间段内执行一次作业任务或是在指定的时间间隔内多次执行作业任务,SimpleTrigger应该能满足你的调度需求.例如,你希望触发器在2015年 ...

  2. Quartz教程五:SimpleTrigger

    原文链接 | 译文链接 | 翻译:nkcoder 本系列教程由quartz-2.2.x官方文档翻译.整理而来,希望给同样对quartz感兴趣的朋友一些参考和帮助,有任何不当或错误之处,欢迎指正:有兴趣 ...

  3. .NET高级代码审计(第五课) .NET Remoting反序列化漏洞

    0x00 前言 最近几天国外安全研究员Soroush Dalili (@irsdl)公布了.NET Remoting应用程序可能存在反序列化安全风险,当服务端使用HTTP信道中的SoapServerF ...

  4. Spring官方文档翻译(1~6章)

    Spring官方文档翻译(1~6章) 转载至 http://blog.csdn.net/tangtong1/article/details/51326887 Spring官方文档.参考中文文档 一.S ...

  5. iOS网络基础---iOS-Apple苹果官方文档翻译

    CHENYILONG Blog iOS网络基础---iOS-Apple苹果官方文档翻译 iOS网络基础 技术博客http://www.cnblogs.com/ChenYilong/ 新浪微博http: ...

  6. Flume官方文档翻译——Flume 1.7.0 User Guide (unreleased version)中一些知识点

    Flume官方文档翻译--Flume 1.7.0 User Guide (unreleased version)(一) Flume官方文档翻译--Flume 1.7.0 User Guide (unr ...

  7. Flume官方文档翻译——Flume 1.7.0 User Guide (unreleased version)(二)

    Flume官方文档翻译--Flume 1.7.0 User Guide (unreleased version)(一) Logging raw data(记录原始数据) Logging the raw ...

  8. NeHe OpenGL教程 第四十五课:顶点缓存

    转自[翻译]NeHe OpenGL 教程 前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线 ...

  9. kali linux 渗透测试视频教程 第五课 社会工程学工具集

    第五课 社会工程学工具集 文/玄魂 教程地址:http://edu.51cto.com/course/course_id-1887.html   目录 第五课社会工程学工具集 SET SET的社会工程 ...

随机推荐

  1. java中hashcode和equals的区别和联系

    HashSet和HashMap一直都是JDK中最常用的两个类,HashSet要求不能存储相同的对象,HashMap要求不能存储相同的键. 那么Java运行时环境是如何判断HashSet中相同对象.Ha ...

  2. 在Mac OS X 10.9上安装nginx

    1. 安装PCRE Download latest PCRE. After download go to download directory from terminal. $ cd ~/Downlo ...

  3. 记录一下在WinXP上搭建Apache的httpd+PHP+MySQL+Wordpress的过程

    实验室有台旧电脑,想用它一台服务器. 不知为何,U盘启动盘死活不能启动,所以放弃了安装Linux的念头,直接在原来的XP上弄一个服务器,毕竟用的人也不多,也就局域网的这几个人, 本来主要是搭建一个FT ...

  4. AlertView with password

    1. setAlertViewStyle:UIAlertViewStyleSecureTextInput UIAlertView *alertView = [[UIAlertView alloc] i ...

  5. android访问webservices

    /** * 手机号段归属地查询(模拟器.HTC 可以) *  * @param phoneSec 手机号段 */ public  void getRemoteInfo() { /*String pho ...

  6. 如何在Swift里用UnsafeMutablePointer

    下午在适配iPadUI的时候,用到了UIPopoverPresentationController,然后在转屏的时候需要调用UIPopoverPresentationControllerDelegat ...

  7. Key Task

    Problem Description The Czech Technical University is rather old - you already know that it celebrat ...

  8. SAP ABAP程序下载器(增强版)

    在实际的项目中运用过几次 Mass download 这个程序,发现下载ABAP代码还真是利器,目前最新的版本是1.4.4,已经n年没有更新过了.使用过程中,发现其导出的HTML格式的代码有问题,包括 ...

  9. Cordova 3.0 + Eclipse 开发流程

    cd d:\cordova\projectscordova create HelloWorld com.example.helloworld HelloWorldcd HelloWorldcordov ...

  10. 进程控制之system函数

    ISO C定义了system函数,但是其操作对系统的依赖性很强.POSIX.1包括了system接口,它扩展了ISO C定义,以描述system在POSIX.1环境中的运行行为. #include & ...