- 浏览: 498320 次
- 性别:
- 来自: 深圳
文章分类
- 全部博客 (200)
- java基础 (30)
- ajax (19)
- 乱写 (5)
- groovy (2)
- db (8)
- gwt (0)
- jee (2)
- 我关注的开源 (1)
- RIA AIR (1)
- spring (11)
- lucene (0)
- 工具 (10)
- 百科 (2)
- linux (6)
- android (40)
- 移动开发 (21)
- 代码片断 (15)
- tomcat (1)
- css (1)
- html5 (2)
- jquery (2)
- playframework (3)
- web (2)
- nio (3)
- design (1)
- nosql (3)
- 日志 (12)
- mysql (4)
- 图表 (1)
- python (3)
- ruby (1)
- git (0)
- hibernate (1)
- springboot (1)
- guava (1)
- mybatis (0)
- 工作问题 (3)
- php (1)
最新评论
-
linzm1990:
踩了很多坑啊。。。。
hibernate @Nofound 与@ManyToOne fetch lazy的问题 -
Ccccrrrrrr:
...
转: Spring boot 文件上传 -
rmzdb:
兄弟,你这个东西,在ie内核的浏览器,貌似不识别 文件名
工作问题:http下载文件,中文文件名在firefox下乱码问题 -
107x:
问题解决了,谢谢!
工作问题:http下载文件,中文文件名在firefox下乱码问题 -
klxqljq:
额鹅鹅鹅
android布局实现头尾固定, 中间多余内容可以滚动
Although briefly described in the official documentation, I believe Quartz plugins aren’t known enough, looking at how useful they are.
Essentially plugins in Quartz are convenient classes wrapping registration of underlying listeners. You are free to write your own plugins but we will focus on existing ones shipped with Quartz.
LoggingTriggerHistoryPlugin
First some background. Two main abstractions in Quartz are jobs and triggers. Job is a piece of code that we would like to schedule. Trigger instructs the scheduler when this code should run. CRON (e.g. run every Friday between 9 AM and 5 PM until November) and simple (run 100 times every 2 hours) triggers are most commonly used. You associate any number of triggers to a single job.
Believe it or not, Quartz by default provides no logging or monitoring whatsoever of executed jobs and triggers. There is an API, but no built-in logging is implemented. It won’t show you that it now executes this particular job due to this trigger firing. So the first thing you should do is adding the following lines to your quartz.properties:
org.quartz.plugin.triggerHistory.class=org.quartz.plugins.history.LoggingTriggerHistoryPlugin org.quartz.plugin.triggerHistory.triggerFiredMessage=Trigger [{1}.{0}] fired job [{6}.{5}] scheduled at: {2, date, dd-MM-yyyy HH:mm:ss.SSS}, next scheduled at: {3, date, dd-MM-yyyy HH:mm:ss.SSS} org.quartz.plugin.triggerHistory.triggerCompleteMessage=Trigger [{1}.{0}] completed firing job [{6}.{5}] with resulting trigger instruction code: {9}. Next scheduled at: {3, date, dd-MM-yyyy HH:mm:ss.SSS} org.quartz.plugin.triggerHistory.triggerMisfiredMessage=Trigger [{1}.{0}] misfired job [{6}.{5}]. Should have fired at: {3, date, dd-MM-yyyy HH:mm:ss.SSS}
The first line (and the only required) loads the plugin class LoggingTriggerHistoryPlugin. The remaining lines are configuring the plugin, customizing the logging messages. I found the built-in defaults not very well thought, e.g. they display current time which is already part of the logging framework message. You are free to construct any logging message, see the API for details. Adding these extra few lines makes debugging and monitoring much easier:
LoggingTriggerHistoryPlugin | Trigger [Demo.Every-few-seconds] fired job [Demo.Print-message] scheduled at: 04-04-2012 23:23:47.036, next scheduled at: 04-04-2012 23:23:51.036 //...job output LoggingTriggerHistoryPlugin | Trigger [Demo.Every-few-seconds] completed firing job [Demo.Print-message] with resulting trigger instruction code: DO NOTHING. Next scheduled at: 04-04-2012 23:23:51.036
You see now why naming your triggers (Demo.Every-few-seconds) and jobs (Demo.Print-message) is so important.
LoggingJobHistoryPlugin
There is another handy plugin related to logging:
org.quartz.plugin.jobHistory.class=org.quartz.plugins.history.LoggingJobHistoryPlugin org.quartz.plugin.jobHistory.jobToBeFiredMessage=Job [{1}.{0}] to be fired by trigger [{4}.{3}], re-fire: {7} org.quartz.plugin.jobHistory.jobSuccessMessage=Job [{1}.{0}] execution complete and reports: {8} org.quartz.plugin.jobHistory.jobFailedMessage=Job [{1}.{0}] execution failed with exception: {8} org.quartz.plugin.jobHistory.jobWasVetoedMessage=Job [{1}.{0}] was vetoed. It was to be fired by trigger [{4}.{3}] at: {2, date, dd-MM-yyyy HH:mm:ss.SSS}
The rule is the same – plugin + extra configuration. See JavaDoc of LoggingJobHistoryPlugin for details and possible placeholders. Quick look at logs reveals very descriptive output:
Trigger [Demo.Every-few-seconds] fired job [Demo.Print-message] scheduled at: 04-04-2012 23:34:53.739, next scheduled at: 04-04-2012 23:34:57.739 Job [Demo.Print-message] to be fired by trigger [Demo.Every-few-seconds], re-fire: 0 //...job output Job [Demo.Print-message] execution complete and reports: null Trigger [Demo.Every-few-seconds] completed firing job [Demo.Print-message] with resulting trigger instruction code: DO NOTHING. Next scheduled at: 04-04-2012 23:34:57.739
I have no idea why these plugins aren’t enabled by default. After all, if you don’t want such a verbose output, you can turn it off in your logging framework. Never mind, I think it is a good idea to have them in place when troubleshooting Quartz execution.
XMLSchedulingDataProcessorPlugin
This is a pretty comprehensive plugin. It reads XML file (by default named quartz_data.xml) containing jobs and triggers definitions and adds them to the scheduler. This is especially useful when you have a global job that you need to add once. Plugin can either update the existing jobs/triggers or ignore the XML file if they already exist – very useful when JDBCJobStore is used.
org.quartz.plugin.xmlScheduling.class=org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin
In the aforementioned article we have been manually adding job to the scheduler:
val trigger = newTrigger(). withIdentity("Every-few-seconds", "Demo"). withSchedule( simpleSchedule(). withIntervalInSeconds(4). repeatForever() ). build() val job = newJob(classOf[PrintMessageJob]). withIdentity("Print-message", "Demo"). usingJobData("msg", "Hello, world!"). build() scheduler.scheduleJob(job, trigger)
The same can be achieved with XML configuration, just place the following quartz_data.xml in your CLASSPATH:
<?xml version="1.0" encoding="UTF-8"?> <job-scheduling-data xmlns="http://www.quartz-scheduler.org/xml/JobSchedulingData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.quartz-scheduler.org/xml/JobSchedulingData http://www.quartz-scheduler.org/xml/job_scheduling_data_2_0.xsd "> <processing-directives> <overwrite-existing-data>false</overwrite-existing-data> <ignore-duplicates>true</ignore-duplicates> </processing-directives> <schedule> <trigger> <simple> <name>Every-few-seconds</name> <group>Demo</group> <job-name>Print-message</job-name> <job-group>Demo</job-group> <repeat-count>-1</repeat-count> <repeat-interval>4000</repeat-interval> </simple> </trigger> <job> <name>Print-message</name> <group>Demo</group> <job-class>com.blogspot.nurkiewicz.quartz.demo.PrintMessageJob</job-class> <job-data-map> <entry> <key>msg</key> <value>Hello, World!</value> </entry> </job-data-map> </job> </schedule> </job-scheduling-data>
The same can be achieved with XML configuration, just place the following quartz_data.xml in your CLASSPATH:
org.quartz.plugin.xmlScheduling.fileNames=/etc/quartz/system-jobs.xml,/home/johnny/my-jobs.xml org.quartz.plugin.xmlScheduling.scanInterval=60
ShutdownHookPlugin
Last but not least, ShutdownHookPlugin. Small but probably useful plugin that register shutdown hook in the JVM in order to gently stop the scheduler. However I recommend turning cleanShutdown off – if the system already tries to abruptly stop the application (typically scheduler shutdown is called by Spring via SchedulerFactoryBean) or the user hit Ctrl+C – waiting for currently running jobs seems like a bad idea. After all, maybe we are killing the application because some jobs are running for too long/hunging?
org.quartz.plugin.shutdownHook.class=org.quartz.plugins.management.ShutdownHookPlugin org.quartz.plugin.shutdownHook.cleanShutdown=false
As you can see Qurtz ships with few quite interesting plugins. For some reason they aren’t described in detail in the official documentation, but they work pretty well and are a valuable addition to scheduler.
The source code with applied plugins is available on GitHub.
发表评论
-
浅谈 SpringMVC 数据绑定
2014-10-16 17:20 1045转自: http://senton.iteye.com/blo ... -
转: 当spring 容器初始化完成后执行某个方法
2014-05-05 14:09 1746转自: http://www.cnblogs.com/roll ... -
Configuring Quartz with JDBCJobStore in Spring
2014-02-21 10:57 1004I am starting a little series a ... -
quatrz 任务监控管理 (2)
2009-11-04 12:53 1777转自:http://sundoctor.iteye.com/b ... -
Quartz任务监控管理
2009-11-04 12:18 5847转自 http://sundoctor.iteye.com/b ... -
Quartz 在 Spring 中如何动态配置时间
2009-11-04 12:06 3167转自: http://www.iteye.com/topic/ ... -
Quartz在Spring中动态设置cronExpression(自己写类从数据库里读取)
2009-11-04 11:39 4966什么是动态定时任务? 是由客户制定生成的,服务端只知道该去 ... -
Spring邮件发送
2009-11-04 08:21 36681、单例模式(单发,群 ... -
spring源码解读系列(收集)
2009-09-22 09:04 1427对org.springframework.beans.Cach ... -
如何在基于注解风格的Spring-MVC中使用拦截器
2009-09-22 08:27 4766转自 http://www.blogjava.net/ate ...
相关推荐
quartz scheduler getting started 的翻译
Quartz is a full-featured, open source job scheduling service that can be integrated with, or ... The Quartz Scheduler includes many enterprise-class features, such as JTA transactions and clustering.
Quartz_Scheduler_Configuration_Guide.pdf Version2.2.1
本资源是一个最新 Spring 4.2.2 集成 Quartz Scheduler 2.2.2 的一个简单的 demo,也是博客《最新 Spring 4.2.2 集成 Quartz Scheduler 2.2.2 任务调度示例》的配套示例项目,该博客地址是:...
Winder 是一个基于 Quartz Scheduler 的简单状态机。它有助于在 Quartz Scheduler 上编写多个步骤任务。Winder 源于一种在 eBay Cloud 中广泛使用的状态机。eBay 平台即服务(PaaS)使用它来将软件部署到数十万个...
shiro+SpringMVC+Spring+mybatis+maven+mybatis 自动刷新+ Quartz scheduler 定时器管理
里面有个简单的quartz-scheduler java示例。
Getting_Started_with_Quartz_Scheduler.pdf Version 2.2.1
Quartz中文入门教程 前言 Quartz让任务调度简单 ...用调度器(Scheduler)调用你的作业 编程调度同声明性调度 有状态和无状态作业 Quartz框架的其他特征 Quartz下一步计划 了解更多Quartz特征
QuartzScheduler-core 模拟 源代码:dotnet run --register-service --urls http:// *:5080 或发布:dotnet。\ QuartzScheduler.Web.dll --register-service --urls http:// *:5080
Quartz官方API文档,最新2.2.1版
Spring Boot Quartz Scheduler示例:构建电子邮件调度应用 完整的教程: : 要求 Java-1.8.x Maven-3.xx MySQL-5.xx 设定步骤 1.克隆应用程序 git clone ...
很不错的quarts scheduler的学习书籍,能帮助初学者快速的入门quarts scheduler框架和运用。
Maven坐标:org.quartz-scheduler:quartz:2.3.2; 标签:quartz、scheduler、中文文档、jar包、java; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性化翻译,文档中的...
Quartz Scheduler的Spring-Boot自动配置只是Quartz Scheduler的Spring-Boot启动器。 当然,Quartz Scheduler已经有好几个启动器,但是它们都不能满足我的所有需求,因此我创建了自己的启动器。 这只是一个业余项目。...
Quartz_Scheduler_Example_Programs_and_Sample_Code.pdf Version 2.2.1
使用Quartz调度任务,根据需要人为的终止某个任务,适用于很多常见的场景
石英-redis-jobstore 使用 JobStore。 该项目的灵感来自 ,并提供了相似的功能,但有一些主要区别: Redis数据库和密钥前缀是...配置在quartz.properties文件中可以设置以下属性: # set the scheduler's JobStore cla
crystal-demo:用于Spring Boot 2和Quartz Scheduler集成的演示项目