quartz 添加监听器listener
全局注册,所有Job都会起作用
JobCountListener listener = new JobCountListener();
sched.getListenerManager().addJobListener(listener);
给固定的job添加监听器
JobCountListener listener = new JobCountListener();
Matcher<JobKey> matcher = KeyMatcher.keyEquals(new JobKey("hello3", "group1"));
scheduler.getListenerManager().addJobListener(listener, matcher);
指定一组任务
GroupMatcher<JobKey> matcher = GroupMatcher.jobGroupEquals("group1");
sched.getListenerManager().addJobListener(new MyJobListener(), matcher);
可以根据组的名字匹配开头和结尾或包含
JobCountListener listener = new JobCountListener();
GroupMatcher<JobKey> matcher = GroupMatcher.groupStartsWith("g");
//GroupMatcher<JobKey> matcher = GroupMatcher.groupContains("g");
scheduler.getListenerManager().addJobListener(listener, matcher);
/**
* @author sky
*/
public class JobCountListener implements org.quartz.JobListener {
private Integer count; public String getName() {
return "job监听";
} public void jobToBeExecuted(JobExecutionContext jobExecutionContext) {
System.out.println("任务执行前。");
} public void jobExecutionVetoed(JobExecutionContext jobExecutionContext) {
System.out.println("如果当TriggerListener中的vetoJobExecution方法返回true时,那么执行这个方法。任务被终止");
} public void jobWasExecuted(JobExecutionContext jobExecutionContext, JobExecutionException e) {
JobDetail jobDetail = jobExecutionContext.getJobDetail();
System.out.println("Job :" + jobDetail.getKey().getGroup() + "." + jobDetail.getKey().getName());
Integer current = (Integer) jobExecutionContext.getJobDetail().getJobDataMap().get("count");
System.out.println("调用次数:" + current);
} }
package com.sky.JobSchedule.Job; import org.quartz.*;
import org.springframework.stereotype.Component; import java.text.SimpleDateFormat;
import java.util.Date; /**
* @author sky
*/
@Component
@DisallowConcurrentExecution
@PersistJobDataAfterExecution
public class JobCron implements Job {
String name; public JobCron() {
System.out.println("Hello, Quartz sky! ----------------------");
} public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap();
Integer count = (Integer) jobDataMap.get("count");
if(count==null){
count=0;
}
count++;
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); System.out.println("Hello, " + count + " sky !" + formatter.format(new Date()));
jobExecutionContext.getJobDetail().getJobDataMap().put("count", count);
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
}
}
重启服务,需要重新添加监听器。
quartz 添加监听器listener的更多相关文章
- [C#][Quartz]添加监听器
namespace Quartz.Listener { public class SchedulerListener : SchedulerListenerSupport { private stat ...
- 过滤器(Filter)、拦截器(Interceptor)、监听器(Listener)
一.Filter 过滤器 1.简介 Filter也称之为过滤器,它是Servlet技术中最实用的技术,WEB开发人员通过Filter技术,对web服务器管理的所有web资源:例如Jsp, Servle ...
- Quartz任务监听器
在Quartz框架提供了JobListener接口,可在任务执行前.任务被拒绝及任务执行完成后实现对任务的拦截,该接口的声明如下: public interface JobListener { /** ...
- javaweb学习总结(四十七)——监听器(Listener)在开发中的应用
监听器在JavaWeb开发中用得比较多,下面说一下监听器(Listener)在开发中的常见应用 一.统计当前在线人数 在JavaWeb应用开发中,有时候我们需要统计当前在线的用户数,此时就可以使用监听 ...
- javaWeb学习总结(11)- 监听器(Listener)在开发中的应用
监听器在JavaWeb开发中用得比较多,下面说一下监听器(Listener)在开发中的常见应用 一.统计当前在线人数 在JavaWeb应用开发中,有时候我们需要统计当前在线的用户数,此时就可以使用监听 ...
- java之Servlet监听器Listener
常用应用场景:单点登录.统计在线人数 一.简介 (一)概述 1.Listener 用于监听 java web程序中的事件,例如创建.修改.删除Session.request.context等,并触发响 ...
- JAVA监听器Listener
JAVA监听器Listener 一. 简介 监听器用于对web中内置对象的状态或者属性变化进行监听并做出相应响应的一种Servlet;在内置对象的生命周期中,产生.销毁等状态发生变化时,监听器就会进行 ...
- JavaWeb学习 (二十七)————监听器(Listener)在开发中的应用
监听器在JavaWeb开发中用得比较多,下面说一下监听器(Listener)在开发中的常见应用 一.统计当前在线人数 在JavaWeb应用开发中,有时候我们需要统计当前在线的用户数,此时就可以使用监听 ...
- Servlet 监听器Listener详解
转自:http://blog.csdn.net/u012228718/article/details/41730799 一.简介 (一)概述 1.Listener 用于监听 Javaweb程序中的事件 ...
随机推荐
- POJ 2311 Cutting Game(SG函数)
题目描述 意思就是说两个人轮流剪纸片,直到有一个人剪出1*1的方格就算这个人赢了.然后给出纸片的长和宽,求先手会赢还是会输 (1<=n,m<=200) 题解 看了一眼,这不是裸的SG吗 啪 ...
- session 超时跳转登陆页面
/** * session超时跳转登陆页面 * @author zhangdong * 2017年10月24日 */ @Aspect @Component public class SessionTi ...
- JavaScript函数写法整理
1.普通函数定义的两种写法 function hello(){ console.log("hello!"); } var hello = function(){ console.l ...
- iview中单击行,使得checkbox状态的方法
直接贴代码,这是一组jquery全选,全不选,反选代码 <!DOCTYPE html> <html lang="en"> <head> < ...
- 紫书 习题8-18 UVa 11536 (扫描法)
这道题貌似可以用滑动窗口或者单调栈做, 但是我都没有用到. 这道题要求连续子序列中和乘上最小值最大, 那么我们就可以求出每一个元素, 以它为最小值的的最大区间的值, 然后取max就ok了.那么怎么求呢 ...
- Github README.md中添加图片
1.先把图片上传到你的项目中:然后在github网站上按路径打开图片,如下打开的图片链接: 2.复制图片的地址 3.然后在README.md写上:  注意 ...
- Mysql学习总结(23)——MySQL统计函数和分组查询
1.使用count统计条数:select count(字段名...) from tablename; 2.使用avg计算字段的平均值:select avg(字段名) from tablename: 这 ...
- Fiddler(Web/HTTP调试利器)
简述 Fiddler是一个http协议调试代理工具,它能够记录并检查所有你的电脑和互联网之间的http通讯,设置断点,查看所有的"进出"Fiddler的数据(指cookie.htm ...
- Step by Step Do IOS Swift CoreData Simple Demo
简单介绍 这篇文章记录了在 IOS 中使用 Swift 操作 CoreData 的一些基础性内容,因为缺乏文档,基本上都是自行实验的结果.错漏不可避免,还请谅解. 部分内容借鉴了 Tim Roadle ...
- 曲根英语万词---二、evoke
曲根英语万词---二.evoke 一.总结 一句话总结:evoke v.唤起,引起 词根:-voc-, -vok- [词根含义]:声音,叫喊 1.consecrate? v,供奉,奉为神圣 -ate, ...