博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Quartz Scheduler(2.2.1) - Working with TriggerListeners and JobListeners
阅读量:4316 次
发布时间:2019-06-06

本文共 2583 字,大约阅读时间需要 8 分钟。

TriggerListeners and JobListeners

Listeners are objects that you create to perform actions based on events occurring within the scheduler. As indicated by their names, TriggerListeners receive events related to triggers, and JobListeners receive events related to jobs.

TriggerListener

Trigger-related events include: trigger firings, trigger misfirings, and trigger completions (the jobs fired off by the trigger is finished).

The org.quartz.TriggerListener Interface

public interface TriggerListener {     public String getName();     public void triggerFired(Trigger trigger, JobExecutionContext context);     public boolean vetoJobExecution(Trigger trigger, JobExecutionContext context);     public void triggerMisfired(Trigger trigger);     public void triggerComplete(Trigger trigger, JobExecutionContext context, int triggerInstructionCode); }

JobListener

Job-related events include: a notification that the job is about to be executed, and a notification when the job has completed execution.

The org.quartz.JobListener Interface

public interface JobListener {     public String getName();     public void jobToBeExecuted(JobExecutionContext context);     public void jobExecutionVetoed(JobExecutionContext context);     public void jobWasExecuted(JobExecutionContext context, JobExecutionException jobException); }

 

Creating Your Own Listeners

To create a listener, simply create an object that implements the org.quartz.TriggerListener and/or org.quartz.JobListener interface.

Listeners are then registered with the scheduler at run time, and must be given a name (or rather, they must advertise their own name via their getName() method).

For your convenience, rather than implementing these interfaces, your class could also extend the class JobListenerSupport or TriggerListenerSupport and simply override the events you're interested in.

Listeners are registered with the scheduler's ListenerManager along with a Matcher that describes the Jobs/Triggers for which the listener wants to receive events.

Listeners are not used by most users of Quartz, but are handy when application requirements create the need for the notification of events, without the Job itself having to explicitly notify the application

Code Samples for Adding Listeners

The following code samples illustrate ways to add JobListeners with interest in different types of jobs. Adding TriggerListeners works in a the same way.

scheduler.getListenerManager().addJobListener(myJobListener, KeyMatcher.jobKeyEquals(new JobKey("myJobName", "myJobGroup")));

 

转载于:https://www.cnblogs.com/huey/p/5108822.html

你可能感兴趣的文章
No qualifying bean of type available问题修复
查看>>
第四周助教心得体会
查看>>
spfile
查看>>
Team Foundation Service更新:改善了导航和项目状态速查功能
查看>>
WordPress资源站点推荐
查看>>
Python性能鸡汤
查看>>
android Manifest.xml选项
查看>>
Cookie/Session机制具体解释
查看>>
ATMEGA16 IOport相关汇总
查看>>
有意思的cmd命令
查看>>
js正則表達式语法
查看>>
Git学习系列-Git基本概念
查看>>
c#多个程序集使用app.config 的解决办法
查看>>
Linux+Apache+PHP+MySQL服务器环境配置(CentOS篇)
查看>>
Linux下获取本机IP地址的代码
查看>>
(C#)调用Webservice,提示远程服务器返回错误(500)内部服务器错误
查看>>
flex布局
查看>>
python-----python的文件操作
查看>>
java Graphics2d消除锯齿,使字体平滑显示
查看>>
控件中添加的成员变量value和control的区别
查看>>