- 浏览: 780164 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (386)
- Linux (36)
- Tomcat (6)
- windows (8)
- Apache (10)
- Java (25)
- jquery (7)
- Jquery 插件 (3)
- Oracle (5)
- Oracle SQL (68)
- Spring (15)
- 开发工具 (6)
- Struts (20)
- js (14)
- Project Code (2)
- Project Code Tomcat (1)
- libset (1)
- JSP (8)
- arithmetic (2)
- 浏览器 (1)
- extjs (3)
- 学习网站 (5)
- 生活情感 (0)
- 电话号码算法 (3)
- 快捷键 (1)
- 转载 (1)
- Dos命令 (2)
- services (1)
- Resources (1)
- 行业积累 (3)
- 项目积累 (3)
- Web (3)
- 文档 (1)
- JavaEE (2)
- JSF (3)
- http (3)
- JS窗口 (1)
- Html (4)
- Flex (1)
- 资讯 (2)
- 项目规范 (1)
- Struts s:property textarea中默认值用 (1)
- Quartz 2.0.2 (12)
- 1天有多少毫秒 (1)
- 专题 (1)
- intellij idea 10 CD-KEY (1)
- restlet (4)
- Mail (1)
- Excel (3)
- Menu (1)
- Big Data技术综述 (1)
- Quart 1 (1)
- nosql (1)
- linux远程 (1)
- jdk (5)
- wind7 (1)
- 虚拟人 (0)
- 虚拟机 (1)
- 终端 (1)
- Ubuntu (16)
- Myeclipse (2)
- Wmware (1)
- eclipse (2)
- css (2)
- csv (1)
- 开源 (1)
- plsql (2)
- cassandra (4)
- maven (1)
- hadoop (2)
- mysql (1)
- spring security (1)
- tools (1)
- jdbc (2)
- exception (2)
- 硬盘数据备份 (1)
- dwr (1)
- svn (1)
- PowerDesigner15使用时的十五个问题 (1)
- tomcat 项目发部路径 (1)
- js 暂停执行 (1)
- jquery jqgrid 格式化数据显示 (1)
- js 代码模板 (1)
- strutss2 直接跳转到jsp页面 (1)
- servlet (1)
- jdbc spring (1)
- js学习网站 (1)
- 自学考试 (2)
- hibernate (2)
- eos (1)
- c (4)
- 黑马 (2)
- 大数据 (2)
- 实战云大数据案例分享 (0)
- Spark (2)
- Flink (1)
最新评论
-
coosummer:
推荐使用http://buttoncssgenerator.c ...
jquery button 漂亮 -
thinktothings:
Array_06 写道你好,我是一名刚毕业学生,我以后就是做J ...
如何转型架构师 -
thinktothings:
软考,考有职业资格证,有系统的知识体系学习
如何转型架构师 -
Array_06:
你好,我是一名刚毕业学生,我以后就是做Java的架构师,那请问 ...
如何转型架构师 -
beykery:
你这也太复杂了。。。。jsf2不应该是这样的。。。。
JSF2.0的一个简单Demo
Quartz Enterprise Job Scheduler Tutorial
Lesson 5: SimpleTrigger
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).
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:
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:
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();
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 .withSchedule(simpleSchedule() .withIntervalInSeconds(10) .withRepeatCount(10)) // note that 10 repeats will give a total of 11 firings .forJob(myJob) // identify job with handle to its JobDetail itself .build();
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();
Build a trigger that will fire now, then repeat every five minutes, until the hour 22:00:
trigger = newTrigger() .withIdentity("trigger7", "group1") .withSchedule(simpleSchedule() .withIntervalInMinutes(5) .repeatForever()) .endAt(dateOf(22, 0, 0)) .build();
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")) .withSchedule(simpleSchedule() .withIntervalInHours(2) .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(); 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.
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
MISFIRE_INSTRUCTION_IGNORE_MISFIRE_POLICY MISFIRE_INSTRUCTION_FIRE_NOW MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_EXISTING_REPEAT_COUNT MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_REMAINING_REPEAT_COUNT MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_REMAINING_COUNT MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_EXISTING_COUNT
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):
trigger = newTrigger() .withIdentity("trigger7", "group1") .withSchedule(simpleSchedule() .withIntervalInMinutes(5) .repeatForever() .withMisfireHandlingInstructionNextWithExistingCount()) .build();
- quartz-2.0.2-examples.zip (965.8 KB)
- 下载次数: 4
发表评论
-
quartz 执行时间配置
2011-09-26 10:23 2515CronTrigger Tutorial Intro ... -
1天有多少毫秒
2011-07-28 14:43 18611、 --1天有多少毫秒 1天=86400000 ... -
Lesson 7: TriggerListeners and c
2011-07-27 14:41 1667Quartz Enterprise Job Scheduler ... -
Lesson 6: CronTrigger
2011-07-27 14:28 1285Quartz Enterprise Job Scheduler ... -
Lesson 4: More About Triggers
2011-07-27 14:14 1101Quartz Enterprise Job Scheduler ... -
Lesson 3: More About Jobs and Job Details
2011-07-27 11:58 1370Quartz Enterprise Job Scheduler ... -
Lesson 2: The Quartz API, and Introduction to Jobs And Triggers
2011-07-27 11:34 1296Quartz Enterprise Job Scheduler ... -
Lesson 1: Using Quartz
2011-07-27 11:22 1086Quartz Enterprise Job Scheduler ... -
Examples Overview
2011-07-27 10:24 1026Examples Overview Welcome to t ... -
CronTrigger Tutorial
2011-07-27 10:04 1098http://www.quartz-scheduler.o ... -
quartz-2.0.2-examples
2011-07-27 07:58 1491Cron Triggers Expression ...
相关推荐
《Lesson 1: 使用Quartz》 在IT领域,任务调度是系统自动化的重要组成部分,而Quartz是一款功能强大且广泛使用的Java作业调度框架。本文将深入探讨如何利用Quartz进行任务管理和执行,以及其在实际项目中的应用。 ...
5. **工具支持**: 除了编程方式配置,Quartz还提供了基于XML或数据库的配置方式,以及管理工具如QuartzAdmin,方便用户可视化管理和监控任务。 6. **QuartzDemo**: 压缩包中的"QuartzDemo"可能是包含了一个...
Quertz中提供了两类触发器为:SimpleTrigger,CronTrigger。前者用于实现比较简单的定时功能,例如几点开始,几 点结束,隔多长时间执行,共执行多少次等,后者提供了使用表达式来描述定时功能,因此适用于比较复杂的...
标题中的 "固定时间间隔计划" 指的是使用 Quartz 的 SimpleTrigger 类来设置间隔时间执行任务的方式,而 "Calendar 和 Cron" 提到了另外两种时间触发器,它们提供了更复杂的调度策略。 1. **SimpleTrigger**: ...
### 5. 过时处理策略 过时处理策略对于系统稳定性和任务的正确执行至关重要。scheduler提供多种策略来应对任务未能在预定时间执行的情况(称为“过时”),例如: - **MISFIRE_INSTRUCTION_FIRE_NOW**:立即执行一...
本说明文档将详细解析两种常见的触发器:SimpleTrigger和CronTrigger的配置与使用。 首先,SimpleTrigger适用于那些需要简单定时任务的场景。例如,如果你想让某个任务在特定时间启动,并按设定的间隔重复执行,...
5. **Quartz 手册 java 版-(五) SimpleTrigger**:SimpleTrigger 是一种基础的触发器,用于按照固定间隔重复执行 Job。开发者需要了解如何设置重复次数、间隔时间和结束时间。 6. **Quartz 手册 java 版-(六)...
5. **SimpleTrigger**:SimpleTrigger是最简单的触发器,用于设定固定间隔的重复执行,如每隔多少秒、分钟、小时执行一次。 6. **持久化**:Quartz支持Job和Trigger的持久化存储,这使得在Scheduler重启后,之前的...
3. **SimpleTrigger**:SimpleTrigger则用于定义基于时间间隔的重复执行,如每隔10秒执行一次。可以设置重复次数和结束时间。 4. **JobDetail**:JobDetail定义了作业的详细信息,包括作业的类、组名和关联的数据。...
- **org.quartz.SimpleTrigger**: SimpleTrigger类,定义简单的延时和重复执行规则。 3. **配置与使用** - **XML配置**: Quartz可以通过XML配置文件定义Job和Trigger,方便管理和维护。 - **代码配置**: 也可以...
10. **触发器类型**:SimpleTrigger按照固定间隔触发任务,而CronTrigger则可以根据Cron表达式,按照特定的时间模式(如每日、每周等)触发任务,考虑到了时区和夏令时的影响。 总的来说,Quartz 是一个功能丰富的...
- **Trigger**:触发器,定义何时运行Job,可以是SimpleTrigger(简单触发器)或CronTrigger(cron表达式触发器)等。 - **JobDetail**:包含Job的详细信息,如Job类、数据绑定等。 - **JobDataMap**:Job的参数...
SimpleTrigger可以在指定时间点执行一次或者按照指定的时间间隔重复执行。CronTrigger则更灵活,它允许以cron表达式的形式指定复杂的时间规则。Quartz的配置和使用相对复杂一些,但提供了更加灵活的调度功能。 第三...
- Trigger 定义了 Job 的执行策略,如 SimpleTrigger 或 CronTrigger。 - TriggerBuilder 可以帮助构建 Trigger,例如 `TriggerBuilder.create().withIdentity()` 和 `withSchedule()`。 6. **CronTrigger**: -...
5. **CalendarIntervalTrigger**:除了SimpleTrigger和CronTrigger,还有CalendarIntervalTrigger,用于按日、周、月等时间间隔进行调度。 6. **JobDataMap**:JobDataMap允许你在Job执行时传递参数或数据,它是...
SimpleTrigger用于固定间隔的重复任务,而CronTrigger则可以基于cron表达式,实现更灵活的时间调度。 【项目结构解析】 在`task-examproject-master`中,我们通常会看到以下关键部分: 1. `src/main/java`: 存放...
SimpleTrigger simpleTrigger = new SimpleTrigger("trigger1", "job1", new Date(ts), null, -1, 1000L); // 将 ‘job1’ 加入调度者中 scheduler.scheduleJob(jobDetail, simpleTrigger); // 开始运行调度...
2. **触发器类型**:介绍SimpleTrigger和CronTrigger的区别,SimpleTrigger用于重复执行,CronTrigger则可以根据cron表达式进行复杂的时间安排。 3. **作业执行上下文**:JobDataMap的使用,用于在作业执行时传递...
5. **总结**: 通过Quartz,我们可以轻松地在Java应用程序中实现定时任务,无论是简单的定时执行还是复杂的Cron表达式调度。在Servlet环境下,只需要进行适当的配置,就可以让Quartz在Web应用中无缝工作。Quartz的...
5. **运行环境**:这个demo是在Eclipse环境中运行的,因此可能包含了Eclipse项目文件,如`.project`和`.classpath`,以及必要的依赖库。确保Eclipse已经安装了Quartz库,才能成功运行示例。 在学习这个demo时,你...