Quartz插件的使用

Quartz插件的使用

ID:37894274

大小:41.00 KB

页数:7页

时间:2019-06-02

Quartz插件的使用_第1页
Quartz插件的使用_第2页
Quartz插件的使用_第3页
Quartz插件的使用_第4页
Quartz插件的使用_第5页
资源描述:

《Quartz插件的使用》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、Quartz插件的使用Quartz框架提供了几种用于扩展平台能力的方式。通过使用各种"钩子"(通常指的就是扩展点),Quartz变得很容易被扩展和定制化来适应你的需要。其中一个最简单的扩展框架的方法就是使用Quartz插件。本章就来看看如何使用插件机制让Quartz进入到之前Quartz用户没去过的领域。一、使用Quartz自带插件范例下面将使用插件实现从XML得到JOB,不用手工的把job和trigger加到Scheduler中去再来运行,这样就很方便。如果要更改任务,直接在xml中配置就可以了。不用再写Java代码。1、首先是job类:[java]viewplaincopypackag

2、ecom.mucfc;importjava.util.Date;importjava.util.Set;importorg.quartz.DisallowConcurrentExecution;importorg.quartz.InterruptableJob;importorg.quartz.Job;importorg.quartz.JobDataMap;importorg.quartz.JobExecutionContext;importorg.quartz.JobExecutionException;importorg.quartz.JobKey;importorg.quartz.P

3、ersistJobDataAfterExecution;importorg.quartz.UnableToInterruptJobException;importorg.slf4j.Logger;importorg.slf4j.LoggerFactory;@PersistJobDataAfterExecution@DisallowConcurrentExecutionpublicclassSimpleJobimplementsJob{privatestaticLoggerlog=LoggerFactory.getLogger(SimpleJob.class);privateJobKeyjo

4、bkey=null;@Overridepublicvoidexecute(JobExecutionContextcontext)throwsJobExecutionException{jobkey=context.getJobDetail().getKey();log.info("Excutingjob:"+jobkey+"executingat"+newDate()+"fireby:"+context.getTrigger().getKey());if(context.getMergedJobDataMap().size()>0){Setkeys=context.getM

5、ergedJobDataMap().keySet();for(Stringkey:keys){Stringvalue=context.getMergedJobDataMap().getString(key);log.info("jobdatamapentry:"+key+"="+value);}context.setResult("hello");}}}2、job触发时间配置,使用quartz_data.xml[html]viewplaincopy

6、w.quartz-scheduler.org/xml/JobSchedulingData"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.quartz-scheduler.org/xml/JobSchedulingDatahttp://www.quartz-scheduler.org/xml/job_scheduling_data_1_8.xsd"version="1.8">*<

7、/delete-jobs-in-group>*