Lesson 5: SimpleTrigger_秋名山的放牛娃的博客-程序员秘密

技术标签: Quartz定时器  


SimpleTrigger should meet your scheduling needs if you need to have a job execute exactly once at a specific moment in time, or at a specific moment in time followed by repeats at a specific interval. For example, if you want the trigger to fire at exactly 11:23:54 AM on January 13, 2015, or if you want it to fire at that time, and then fire five more times, every ten seconds.

With this description, you may not find it surprising to find that the properties of a SimpleTrigger include: a start-time, and end-time, a repeat count, and a repeat interval. All of these properties are exactly what you’d expect them to be, with only a couple special notes related to the end-time property.

The repeat count can be zero, a positive integer, or the constant value SimpleTrigger.REPEAT_INDEFINITELY. The repeat interval property must be zero, or a positive long value, and represents a number of milliseconds. Note that a repeat interval of zero will cause ‘repeat count’ firings of the trigger to happen concurrently (or as close to concurrently as the scheduler can manage).

If you’re not already familiar with Quartz’s DateBuilder class, you may find it helpful for computing your trigger fire-times, depending on the startTime (or endTime) that you’re trying to create.

The endTime property (if it is specified) overrides the repeat count property. This can be useful if you wish to create a trigger such as one that fires every 10 seconds until a given moment in time - rather than having to compute the number of times it would repeat between the start-time and the end-time, you can simply specify the end-time and then use a repeat count of REPEAT_INDEFINITELY (you could even specify a repeat count of some huge number that is sure to be more than the number of times the trigger will actually fire before the end-time arrives).




    如果你还不熟悉Quartz的DateBuilder类,你尝试创建日期对象时会发现它非常方便地根据startTime或 endTime参数计算触发器的触发时间。


SimpleTrigger instances are built using TriggerBuilder (for the trigger’s main properties) and SimpleScheduleBuilder (for the SimpleTrigger-specific properties). To use these builders in a DSL-style, use static imports:

SimpleTrigger实例通过TriggerBuilder(for the trigger’s main properties)和SimpleScheduleBuilder(for the SimpleTrigger-specific properties)创建,通过如下代码导入他们的静态方法:

import static org.quartz.TriggerBuilder.*;
import static org.quartz.SimpleScheduleBuilder.*;
import static org.quartz.DateBuilder.*:

Here are various examples of defining triggers with simple schedules, read through them all, as they each show at least one new/different point:

下面是一些defining triggers with simple schedules的例子,可以从中比较他们的异同:

Build a trigger for a specific moment in time, with no repeats:


SimpleTrigger trigger = (SimpleTrigger) newTrigger()
    .withIdentity("trigger1", "group1")
    .startAt(myStartTime) // some Date
    .forJob("job1", "group1") // identify job with name, group strings
Build a trigger for a specific moment in time, then repeating every ten seconds ten times:


trigger = newTrigger()
    .withIdentity("trigger3", "group1")
    .startAt(myTimeToStartFiring)  // if a start time is not given (if this line were omitted), "now" is implied
        .withRepeatCount(10)) // note that 10 repeats will give a total of 11 firings
    .forJob(myJob) // identify job with handle to its JobDetail itself                   

Build a trigger that will fire once, five minutes in the future:


trigger = (SimpleTrigger) newTrigger()
    .withIdentity("trigger5", "group1")
    .startAt(futureDate(5, IntervalUnit.MINUTE)) // use DateBuilder to create a date in the future
    .forJob(myJobKey) // identify job with its JobKey

Build a trigger that will fire now, then repeat every five minutes, until the hour 22:00:

创建一个立马执行的trigger, 每五分钟重复一次, 一直到 22:00:

trigger = newTrigger()
    .withIdentity("trigger7", "group1")
    .endAt(dateOf(22, 0, 0))
Build a trigger that will fire at the top of the next hour, then repeat every 2 hours, forever:


trigger = newTrigger()
    .withIdentity("trigger8") // because group is not specified, "trigger8" will be in the default group
    .startAt(evenHourDate(null)) // get the next even-hour (minutes and seconds zero ("00:00"))
    // note that in this example, 'forJob(..)' is not called
    //  - which is valid if the trigger is passed to the scheduler along with the job  

    scheduler.scheduleJob(trigger, job);

Spend some time looking at all of the available methods in the language defined by TriggerBuilder and SimpleScheduleBuilder so that you can be familiar with options available to you that may not have been demonstrated in the examples above.


Note that TriggerBuilder (and Quartz's other builders) will generally choose a reasonable value for properties that you do not explicitly set. For examples: if you don't call one of the *withIdentity(..)* methods, then TriggerBuilder will generate a random name for your trigger; if you don't call *startAt(..)* then the current time (immediately) is assumed.
另外, TriggerBuilder (以及quartz其他的builders) ,在你没有明确的为一些属性指定值的时候,builder会将其设置为一些有意义的值。比如没有设置 withIdentity() 方法的值时候, TriggerBuilder 会为你的trigger生成一个随机的名字;如果没有调用 startAt() 那默认就是当前的时间。

SimpleTrigger Misfire Instructions

SimpleTrigger has several instructions that can be used to inform Quartz what it should do when a misfire occurs. (Misfire situations were introduced in “Lesson 4: More About Triggers”). These instructions are defined as constants on SimpleTrigger itself (including JavaDoc describing their behavior). The instructions include:

Misfire Instruction Constants of SimpleTrigger

SimpleTrigger 有一些instructions 可以通知quartz在misfire 出现的时候告诉quartz应该做些什么。这些instructionsSimpleTrigger 有对应的常量定义(可以参阅JavaDoc文档)。这些instructions 包括:

SimpleTrigger中的Misfire Instruction 常量


You should recall from the earlier lessons that all triggers have the Trigger.MISFIRE_INSTRUCTION_SMART_POLICY instruction available for use, and this instruction is also the default for all trigger types.

If the ‘smart policy’ instruction is used, SimpleTrigger dynamically chooses between its various MISFIRE instructions, based on the configuration and state of the given SimpleTrigger instance. The JavaDoc for the SimpleTrigger.updateAfterMisfire() method explains the exact details of this dynamic behavior.

When building SimpleTriggers, you specify the misfire instruction as part of the simple schedule (via SimpleSchedulerBuilder):

在先前文章中使用的triggers都默认使用了Trigger.MISFIRE_INSTRUCTION_SMART_POLICY instruction, 这是默认的instruction对于所有的trigger类型来说。

如果smart policy instruciton被使用了,SimpleTrigger会基于configuration和SimpleTrigger instancestate动态的从各种MISFIRE instructions 中选取合适的。可以查看SimpleTrigger.updateAfterMisfire()的JavaDoc文档,详细描述了动态行为的细节。

通过SimpleSchedulerBuilder的simpleSchedule指定misfire instruction:

trigger = newTrigger()
    .withIdentity("trigger7", "group1")

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。




常见移动设备的 CSS3 Media Query 整理(iPhone/iPad/Galaxy)_offbye的博客-程序员秘密

今天帮人解决了iphone4下载页显示错误的问题,css3 media query坑啊,不容易匹配到。/** * iPhone 4/4s landscape & portrait */@media only screenand (min-device-width: 320px)and (max-device-width: 480px)and (-webkit-device-pixel-r



android 手指移动的动画,Android中View跟随手指滑动效果的实例代码_zetachow晓代~的博客-程序员秘密

Android中View跟随手指滑动效果的实例代码发布时间:2020-09-21 08:03:14来源:脚本之家阅读:127作者:meetings本文讲述了Android中View跟随手指滑动效果的实例代码。分享给大家供大家参考,具体如下:1、android View 主要6种滑动方法,分别是layout()offsetLeftAndRight()和offsetTopAndBottom()Layo...


周末也发俩个,正好也在研究wasm一、 如何防止电源正负极接反这个还是要重视啊 我家床单都好多小洞洞了~~~硬件工程师的很多项目是在洞洞板上完成的,但有存在不小心将电源正负极接反的现象,导致很多电子元器件都烧毁,甚至整块板子都废掉,还得再焊接一块,不知道有什么好的办法可以解决?首先粗心不可避免,虽说只是区分正负极两根线,一红一黑,可能接线一次,我们不会出错;接10次线也不会出错,但是1000次?10000呢?


定义此宏的头文件boost\preprocessor\seq\enum.hpp此宏用来将一个序列转换成数组。 举个例子:先定义一个序列,#define BOOST_UNORDERED_PRIMES (17ul)(29ul)(37ul)(53ul)(此序列可以在boost\unordered\detail\util.hpp中找到)BOOST_PP_SEQ_ENUM(BOO


HTML页面转pdf_IT-along的博客-程序员秘密_html 转pdf

HTML页面转pdf工作时,直接传个HTML页面给我,我人被整懵了,通过学习也是解决了这个问题,记录一下使用 flying-saucer-pdf 将HTML转成pdf


Visio 使你能够将复杂的文本和表转换为很难理解的可视化图表,以便快速传达信息。 有许多类型的Visio 图表,包括组织结构图、网络图、工作流和家庭或 office 计划。 Visio 入门可以分为三个基本步骤:使用模板、排列和连接形状以及使用文本修改形状。Visio百度云安装包分享矢量图:iconfont-阿里巴巴矢量图标库模板:visio(99图)[email protected]小-佐-收集_花瓣平面使用教程:快捷方式选择工具 ctrl+1 文字工具 ctrl+2 连接线 ctrl+3 形状工具 .


三级菜单可依次选择进入各子菜单所需新知识点:列表、字典 1 menu = { 2 '北京':{ 3 '海淀':{ 4 '五道口':{ 5 'soho':{}, 6 '网易':{}, 7 'google'...


1. LDAP介绍1.1. LDAP是什么1.2. LDAP是电话簿1.3. LDAP是不是数据库2. LDAP的特点2.1. LDAP的优势2.1.1 跨平台2.1.2 费用及维护2.1.3 复制技术2.1.4 允许使用ACI2.2. LDAP存储什么数据2.3. 什么时候该用LDAP存储数据3. LDAP的基本模型3.1 信息模型:描述LDAP的信息表示方式3.2 命名模型:描述LDAP中的数...


unicode编码表 转载于 近來情轉深的博客:http://jlqzs.blog.163.com/blog/static/2125298320070101826277/ 1 unicode编码表 Unicode目前普遍采用的是UCS-2,它用两个字节来编码一个字符, 比如汉字”经”的编码是0x7ECF,注意字符编码一般用十六进制来 表示,为了与十进制区分,十六进制以0x开头,0x7EC

利用Matlab filterDesigner 工具生成FIR滤波器函数,并调用实现低通滤波_毛毛虫的爹的博客-程序员秘密

https://blog.csdn.net/luobluesky/article/details/89143608function Hd = untitled%UNTITLED Returns a discrete-time filter object.% MATLAB Code% Generated by MATLAB(R) 8.6 and the Signal Processing Toolbox 7.1.% Generated on: 16-Nov-2021 15:19:48% B