quartz本身插件:
LoggingJobHistoryPlugin,LoggingTriggerHistoryPlugin分別可以打印scheduler容器管理的所有triggers和jobDetails的運行日志。 插件XMLSchedulingDataProcessorPlugin
支持使用xml方式管理trigger&job任務(不同於spring對quartz的封裝,但很類似), 一個是支持scheduler的管理的插件。JobInterruptMonitorPlugin監控job執行假死插件(執行時間過長)。ShutdownHookPlugin 捕獲JVM終止的事件,並在調度程序上調用shutdown
我們可以自定義插件
public class QuartzPlugins implements SchedulerPlugin, JobListener {
private String name;
private Scheduler scheduler;
@Override
public void initialize(String s, Scheduler scheduler, ClassLoadHelper classLoadHelper) throws SchedulerException {
this.name = s;
this.scheduler = scheduler;
log.info("--------------------初始化自定義插件 {}-----------------", name);
scheduler.getListenerManager().addJobListener(this, EverythingMatcher.allJobs());
}
@Override
public void start() {
log.info("--------------------啟動自定義插件 {}-----------------", name);
}
@Override
public void shutdown() {
log.info("--------------------關閉自定義插件 {}-----------------", name);
}
/**
* 方法返回一個字符串用以說明 JobListener 的名稱
*/
@Override
public String getName() {
return "spz-spz";
}
/**
* Scheduler 在 JobDetail 將要被執行時調用這個方法
*/
@Override
public void jobToBeExecuted(JobExecutionContext jobExecutionContext) {
log.info("[自定義插件] 被執行時 " + jobExecutionContext.getJobRunTime());
}
/**
* Scheduler 在 JobDetail 即將被執行,但又被 TriggerListener 否決了時調用這個方法。
*/
@Override
public void jobExecutionVetoed(JobExecutionContext jobExecutionContext) {
log.info("[自定義插件] 即將被執行" + jobExecutionContext.getJobRunTime());
}
/**
* Scheduler 在 JobDetail 被執行完畢
*/
@Override
public void jobWasExecuted(JobExecutionContext jobExecutionContext, JobExecutionException e) {
log.info("[自定義插件] JobListener 執行之后" + jobExecutionContext.getJobRunTime());
}
}
