Quartz(二)整合Spring容器中bean及动态调度任务


Quartz 是开源任务调度框架中的翘首,它提供了强大任务调度机制,同时保持了使用的简单性。 
Quartz 允许开发人员灵活地定义触发器的调度时间表,并可以对触发器和任务进行关联映射。 
此外,Quartz提供了调度运行环境的持久化机制,可以保存并恢复调度现场,即使系统因故障关闭,任务调度现场数据并不会丢失。 
此外,Quartz还提供了组件式的侦听器、各种插件、线程池等功能。 

Spring中使用Quartz的3种方法(MethodInvokingJobDetailFactoryBean,implements Job,extends QuartzJobBean) 
以下介绍一下实现job接口的方法,通过此方法可以动态启动,暂定,添加,删除定时功能,可传参数。 
所有数据全部持久化到数据表中,不再需要XML配置文件存储数据。quartz已经封装了持久化方法。数据表用的MYSQL见附件 


Java代码   收藏代码
  1. package com.berheley.bi.basic.timer;  
  2.   
  3. import java.util.Map;  
  4.   
  5. import org.quartz.JobExecutionContext;  
  6.   
  7. import com.berheley.bi.basic.exp.BusinessException;  
  8.   
  9. /** 
  10.  * 类功能描述:定时任务需要实现此接口 
  11.  * 
  12.  * @author      <a href="mailto:qingyu.meng21@gmail.com">mengqingyu </a> 
  13.  * Create:      2010-1-3 上午09:18:51 
  14.  * Description:  
  15.  */  
  16. public interface ITimerJob  
  17. {  
  18.     /** 
  19.      * 定时器执行的任务 
  20.      * @param context 
  21.      * @throws Exception  
  22.      */  
  23.     void jtaTimerExecute(JobExecutionContext context, Map<?, ?> parameters)throws BusinessException;  
  24. }  
  25.   
  26.   
  27.   
  28. package com.berheley.bi.basic.timer;  
  29.   
  30. import org.apache.commons.logging.Log;  
  31. import org.apache.commons.logging.LogFactory;  
  32. import org.quartz.Job;  
  33. import org.quartz.JobDataMap;  
  34. import org.quartz.JobExecutionContext;  
  35. import org.quartz.JobExecutionException;  
  36. import org.springframework.beans.factory.NoSuchBeanDefinitionException;  
  37. import org.webframe.web.util.WebFrameUtils;  
  38.   
  39. import com.berheley.bi.basic.exp.BusinessException;  
  40.   
  41. /** 
  42.  * 类功能描述:定时执行的任务,发布表单 
  43.  * 
  44.  * @author      <a href="mailto:qingyu.meng21@gmail.com">mengqingyu </a> 
  45.  * Create:      2009-12-31 上午12:31:02 
  46.  * Description:  
  47.  */  
  48. public class TimerDataJob implements Job {  
  49.   
  50.     private ITimerJob   timerJob;  
  51.   
  52.     protected Log       log = LogFactory.getLog(getClass());  
  53.   
  54.     @Override  
  55.     public void execute(JobExecutionContext context) throws JobExecutionException {  
  56.         JobDataMap parameters = context.getJobDetail().getJobDataMap();  
  57.         try {  
  58.             Object beanName = parameters.get("beanName");  
  59.             if (beanName == null) {  
  60.                 log.error("JobDataMap 中'beanName'属性值为null!");  
  61.                 return;  
  62.             }  
  63.             timerJob = (ITimerJob) WebFrameUtils.getBean(beanName.toString());  
  64.             timerJob.jtaTimerExecute(context, parameters);  
  65.         } catch (NoSuchBeanDefinitionException e) {  
  66.             log.error("任务ITimerJob接口的实现类(" + e.getBeanName() + ")不存在!");  
  67.         } catch (BusinessException e) {  
  68.             log.error(e.getMessage(), e);  
  69.         }  
  70.     }  
  71. }  
  72.   
  73.   
  74. import java.util.Map;  
  75.   
  76. import org.quartz.JobDetail;  
  77. import org.quartz.Scheduler;  
  78. import org.quartz.Trigger;  
  79.   
  80. import com.berheley.bi.basic.exp.BusinessException;  
  81.   
  82. /** 
  83.  * 类功能描述:定时调度后台管理 
  84.  *  
  85.  * @author <a href="mailto:qingyu.meng21@gmail.com">mengqingyu </a> Create: 2010-1-3 上午09:18:51 
  86.  *         Description: 
  87.  */  
  88. public interface ITimerManageService {  
  89.   
  90.     /** 
  91.      * 获得scheduler 
  92.      */  
  93.     Scheduler getScheduler();  
  94.     /** 
  95.      *  
  96.      * @function:获得任务 
  97.      * @param jobName 
  98.      * @param jobGroup 
  99.      * @return 
  100.      * @throws BusinessException 
  101.      * @author: mengqingyu    2012-10-22 下午03:29:03 
  102.      */  
  103.     JobDetail getJob(String jobName, String jobGroup) throws BusinessException;  
  104.       
  105.     /** 
  106.      *  
  107.      * @function:添加任务 
  108.      * @param jobDetail 
  109.      * @throws BusinessException 
  110.      * @author: mengqingyu    2012-10-22 下午03:29:15 
  111.      */  
  112.     void addJob(JobDetail jobDetail) throws BusinessException;  
  113.       
  114.     /** 
  115.      *  
  116.      * @function:删除任务 
  117.      * @param jobName 
  118.      * @param jobGroup 
  119.      * @throws BusinessException 
  120.      * @author: mengqingyu    2012-10-22 下午03:29:31 
  121.      */  
  122.     void deleteJob(String jobName, String jobGroup) throws BusinessException;  
  123.       
  124.     /** 
  125.      *  
  126.      * @function:立即运行 
  127.      * @param jobName 
  128.      * @param jobGroup 
  129.      * @author: mengqingyu    2012-5-24 上午11:00:20 
  130.      */  
  131.     void addRunNowTrigger(String jobName, String jobGroup) throws BusinessException ;  
  132.   
  133.     /** 
  134.      *  
  135.      * @function:重置定时器 
  136.      * @param jobName 
  137.      * @param jobGroup 
  138.      * @param trigger 
  139.      * @throws BusinessException 
  140.      * @author: mengqingyu    2012-11-30 下午05:22:48 
  141.      */  
  142.     public void rescheduleJob(String triggerName, String triggerGroup, Trigger trigger) throws BusinessException;  
  143.       
  144.     /** 
  145.      *  
  146.      * @function:获得定时器 
  147.      * @param jobName 
  148.      * @param jobGroup 
  149.      * @return 
  150.      * @throws BusinessException 
  151.      * @author: mengqingyu    2012-11-30 下午05:17:09 
  152.      */  
  153.     Trigger getTrigger(String jobName, String jobGroup) throws BusinessException;  
  154.       
  155.     /** 
  156.      *  
  157.      * @function:添加定时 
  158.      * @param trigger 
  159.      * @throws BusinessException 
  160.      * @author: mengqingyu    2012-10-22 下午03:29:41 
  161.      */  
  162.     void addTrigger(Trigger trigger) throws BusinessException;  
  163.       
  164.     /** 
  165.      * 删除定时 
  166.      *  
  167.      * @param triggerName 
  168.      * @param group 
  169.      */  
  170.     void deleteTrigger(String triggerName, String group) throws BusinessException ;  
  171.       
  172.     /** 
  173.      * 暂停定时 
  174.      *  
  175.      * @param triggerName 
  176.      * @param group 
  177.      */  
  178.     void updatePauseTrigger(String triggerName, String group) throws BusinessException ;  
  179.   
  180.     /** 
  181.      * 恢复Trigger 
  182.      *  
  183.      * @param triggerName 
  184.      * @param group 
  185.      */  
  186.     void updateResumeTrigger(String triggerName, String group) throws BusinessException ;  
  187.   
  188.     /** 
  189.      *  
  190.      * @function:保存、修改任务 
  191.      * @param jobName 
  192.      * @param jobGroup 
  193.      * @param description 
  194.      * @throws BusinessException 
  195.      * @author: mengqingyu    2012-10-22 下午03:32:35 
  196.      */  
  197.     void saveOrUpdateJob(String jobName, String jobGroup, String description) throws BusinessException;  
  198.       
  199.     /** 
  200.      *  
  201.      * @function:批量删除任务 
  202.      * @param jobNames 
  203.      * @param jobGroup 
  204.      * @throws BusinessException 
  205.      * @author: mengqingyu    2012-10-22 下午03:33:11 
  206.      */  
  207.     void deleteJobs(String jobNames, String jobGroup) throws BusinessException;  
  208.       
  209.     /** 
  210.      *  
  211.      * @function:查询任务参数 
  212.      * @param jobName 
  213.      * @param jobGroup 
  214.      * @return 
  215.      * @throws BusinessException 
  216.      * @author: mengqingyu    2012-10-22 下午03:34:20 
  217.      */  
  218.     String findJobParams(String jobName, String jobGroup) throws BusinessException;  
  219.       
  220.     /** 
  221.      *  
  222.      * @function:保存任务参数 
  223.      * @param jobName 
  224.      * @param jobGroup 
  225.      * @param key 
  226.      * @param value 
  227.      * @return 
  228.      * @throws BusinessException 
  229.      * @author: mengqingyu    2012-10-22 下午03:38:17 
  230.      */  
  231.     String saveJobParam(String jobName, String jobGroup, String key, String value) throws BusinessException;  
  232.       
  233.     /** 
  234.      *  
  235.      * @function:删除任务参数 
  236.      * @param jobName 
  237.      * @param jobGroup 
  238.      * @param keys 
  239.      * @return 
  240.      * @throws BusinessException 
  241.      * @author: mengqingyu    2012-10-22 下午03:38:26 
  242.      */  
  243.     String deleteJobParams(String jobName, String jobGroup, String keys) throws BusinessException;  
  244.       
  245.     /** 
  246.      *  
  247.      * @function:保存cron 
  248.      * @param params 
  249.      * @throws BusinessException 
  250.      * @author: mengqingyu    2012-10-22 下午03:38:41 
  251.      */  
  252.     void saveCron(Map<String, Object> params) throws BusinessException;  
  253.       
  254.     /** 
  255.      *  
  256.      * @function:保存simple 
  257.      * @param params 
  258.      * @throws BusinessException 
  259.      * @author: mengqingyu    2012-10-22 下午03:40:39 
  260.      */  
  261.     void saveSimple(Map<String, Object> params) throws BusinessException;  
  262.       
  263.     /** 
  264.      *  
  265.      * @function:批量删除定时 
  266.      * @param jobName 
  267.      * @param group 
  268.      * @param triggerNames 
  269.      * @throws BusinessException 
  270.      * @author: mengqingyu    2012-10-22 下午03:41:42 
  271.      */  
  272.     void deleteTriggers(String jobName, String group, String triggerNames) throws BusinessException;  
  273.       
  274.     /** 
  275.      * 根据名称和组别启动和暂停Tigger 
  276.      *  
  277.      * @param triggerName 
  278.      * @param group 
  279.      */  
  280.     String updateStartOrStop(String jobName, String jobGroup) throws BusinessException ;  
  281. }  
  282.   
  283.   
  284. import java.text.ParseException;  
  285. import java.util.ArrayList;  
  286. import java.util.List;  
  287. import java.util.Map;  
  288. import java.util.Map.Entry;  
  289.   
  290. import org.apache.commons.lang.StringUtils;  
  291. import org.quartz.CronTrigger;  
  292. import org.quartz.JobDataMap;  
  293. import org.quartz.JobDetail;  
  294. import org.quartz.Scheduler;  
  295. import org.quartz.SchedulerException;  
  296. import org.quartz.SimpleTrigger;  
  297. import org.quartz.Trigger;  
  298. import org.springframework.beans.factory.annotation.Autowired;  
  299. import org.springframework.stereotype.Service;  
  300. import org.webframe.core.util.DateUtils;  
  301.   
  302. import com.berheley.bi.basic.exp.BusinessException;  
  303. import com.berheley.bi.basic.util.UUIDGenerator;  
  304.   
  305. /** 
  306.  * 类功能描述:通用定时功能 
  307.  *  
  308.  * @author <a href="mailto:qingyu.meng21@gmail.com">mengqingyu </a> 
  309.  * @version $Id: codetemplates.xml,v 1.1 2009/03/06 01:13:01 mengqingyu Exp $ Create: 2011-6-1 
  310.  *          下午05:03:06 
  311.  */  
  312. @Service  
  313. public class TimerManageService implements ITimerManageService {  
  314.   
  315.     @Autowired  
  316.     protected Scheduler scheduler;  
  317.       
  318.     public Scheduler getScheduler() {  
  319.         return scheduler;  
  320.     }  
  321.       
  322.     @Override  
  323.     public JobDetail getJob(String jobName, String jobGroup) throws BusinessException{  
  324.         JobDetail jobDetail;  
  325.         try {  
  326.             jobDetail = scheduler.getJobDetail(jobName, jobGroup);  
  327.         } catch (SchedulerException e) {  
  328.             throw new BusinessException("获取任务失败", e);  
  329.         }  
  330.         return jobDetail;  
  331.     }  
  332.       
  333.     @Override  
  334.     public void addJob(JobDetail jobDetail) throws BusinessException{  
  335.         try {  
  336.             scheduler.addJob(jobDetail, true);  
  337.         } catch (SchedulerException e) {  
  338.             throw new BusinessException("添加任务失败", e);  
  339.         }  
  340.     }  
  341.       
  342.     @Override  
  343.     public void deleteJob(String jobName, String jobGroup) throws BusinessException{  
  344.         try {  
  345.             scheduler.deleteJob(jobName, jobGroup);  
  346.         } catch (SchedulerException e) {  
  347.             throw new BusinessException("删除任务失败", e);  
  348.         }  
  349.     }  
  350.       
  351.     @Override  
  352.     public void addRunNowTrigger(String jobName, String jobGroup) throws BusinessException{  
  353.         try {  
  354.             scheduler.triggerJob(jobName, jobGroup);  
  355.         } catch (SchedulerException e) {  
  356.             throw new BusinessException("立即运行任务失败", e);  
  357.         }  
  358.     }  
  359.   
  360.     @Override  
  361.     public void rescheduleJob(String triggerName, String triggerGroup, Trigger trigger) throws BusinessException{  
  362.         try {  
  363.             scheduler.rescheduleJob(triggerName,triggerGroup,trigger);  
  364.         } catch (SchedulerException e) {  
  365.             throw new BusinessException("重置定时器失败", e);  
  366.         }  
  367.     }  
  368.       
  369.     @Override  
  370.     public Trigger getTrigger(String triggerName, String triggerGroup) throws BusinessException{  
  371.         Trigger trigger;  
  372.         try {  
  373.             trigger = scheduler.getTrigger(triggerName,triggerGroup);  
  374.         } catch (SchedulerException e) {  
  375.             throw new BusinessException("获取定时器失败", e);  
  376.         }  
  377.         return trigger;  
  378.     }  
  379.       
  380.     @Override  
  381.     public void addTrigger(Trigger trigger) throws BusinessException {  
  382.         try {  
  383.             trigger.setVolatility(false);  
  384.             scheduler.scheduleJob(trigger);  
  385.         } catch (SchedulerException e) {  
  386.             throw new BusinessException("添加定时器失败", e);  
  387.         }  
  388.     }  
  389.       
  390.     @Override  
  391.     public void deleteTrigger(String triggerName, String group) throws BusinessException{  
  392.         this.updatePauseTrigger(triggerName, group);  
  393.         try {  
  394.             scheduler.unscheduleJob(triggerName, group);  
  395.         } catch (SchedulerException e) {  
  396.             throw new BusinessException("删除定时任务失败", e);  
  397.         }  
  398.     }  
  399.       
  400.     @Override  
  401.     public void updatePauseTrigger(String triggerName, String group) throws BusinessException{  
  402.         try {  
  403.             scheduler.pauseTrigger(triggerName, group);  
  404.         } catch (SchedulerException e) {  
  405.             throw new BusinessException("停止定时任务失败", e);  
  406.         }  
  407.     }  
  408.   
  409.     @Override  
  410.     public void updateResumeTrigger(String triggerName, String group) throws BusinessException{  
  411.         try {  
  412.             scheduler.resumeTrigger(triggerName, group);  
  413.         } catch (SchedulerException e) {  
  414.             throw new BusinessException("恢复定时任务失败", e);  
  415.         }  
  416.     }  
  417.       
  418.     @Override  
  419.     public void saveOrUpdateJob(String jobName, String jobGroup, String description) throws BusinessException {  
  420.         JobDetail jobDetail;  
  421.         if(StringUtils.isBlank(jobName)){  
  422.             jobName = UUIDGenerator.getUUID();  
  423.             try {  
  424.                 jobDetail = new JobDetail(jobName, jobGroup, Class.forName("com.berheley.bi.basic.timer.TimerDataJob"));  
  425.             } catch (ClassNotFoundException e) {  
  426.                 throw new BusinessException("添加修改任务失败", e);  
  427.             }  
  428.         }  
  429.         else {  
  430.             jobDetail = this.getJob(jobName, jobGroup);  
  431.         }  
  432.         jobDetail.setDescription(description);  
  433.         this.addJob(jobDetail);  
  434.     }  
  435.       
  436.     @Override  
  437.     public void deleteJobs(String jobNames, String group) throws BusinessException {  
  438.         String[] jobs = jobNames.split(",");  
  439.         String[] groups = group.split(",");  
  440.         for(int i=0;i<jobs.length;i++){  
  441.             this.deleteJob(jobs[i], groups[i]);  
  442.         }  
  443.     }  
  444.       
  445.     public String paramMapToList(JobDataMap params) {  
  446.         ArrayList<List<String>> listJobData = new ArrayList<List<String>>();  
  447.         for (Object e: params.entrySet()) {  
  448.             Map.Entry<?, ?> entry = (Entry<?, ?>) e;  
  449.             ArrayList<String> list = new ArrayList<String>();  
  450.             list.add("'" + entry.getKey() + "'");  
  451.             list.add("'" + entry.getValue() + "'");  
  452.             listJobData.add(list);  
  453.         }  
  454.         return listJobData.toString();  
  455.     }  
  456.       
  457.     @Override  
  458.     public String findJobParams(String jobName, String jobGroup) throws BusinessException {  
  459.         JobDetail jobDetail = this.getJob(jobName, jobGroup);  
  460.         return jobDetail == null?"{}":paramMapToList(jobDetail.getJobDataMap());  
  461.     }  
  462.       
  463.     @Override  
  464.     public String saveJobParam(String jobName, String jobGroup, String key, String value) throws BusinessException {  
  465.         JobDetail jobDetail = this.getJob(jobName, jobGroup);  
  466.         JobDataMap params = jobDetail.getJobDataMap();  
  467.         params.put(key, value);  
  468.         this.addJob(jobDetail);  
  469.         return paramMapToList(params);  
  470.     }  
  471.       
  472.     @Override  
  473.     public String deleteJobParams(String jobName, String jobGroup, String keys) throws BusinessException {  
  474.         JobDetail jobDetail = this.getJob(jobName, jobGroup);  
  475.         JobDataMap params = jobDetail.getJobDataMap();  
  476.         String[] key = keys.split(",");  
  477.         for(int i=0;i<key.length;i++){  
  478.             params.remove(key[i]);  
  479.         }  
  480.         this.addJob(jobDetail);  
  481.         return paramMapToList(params);  
  482.     }  
  483.   
  484.     public void initTrigger(Trigger trigger, Map<String, Object> params) {  
  485.         trigger.setDescription(params.get("label").toString());  
  486.         trigger.setJobName(params.get("jobName").toString());  
  487.         trigger.setJobGroup(params.get("group").toString());  
  488.         String startTime = params.get("startTime")==null?"":params.get("startTime").toString();  
  489.         String stopTime = params.get("stopTime")==null?"":params.get("stopTime").toString();  
  490.         if (!StringUtils.isBlank(startTime)) {  
  491.             trigger.setStartTime(DateUtils.parseStringToDate(startTime,"yyyy-MM-dd HH:mm:ss"));  
  492.         }  
  493.         if (!StringUtils.isBlank(stopTime)) {  
  494.             trigger.setEndTime(DateUtils.parseStringToDate(stopTime,"yyyy-MM-dd HH:mm:ss"));  
  495.         }  
  496.     }  
  497.       
  498.     @Override  
  499.     public void saveCron(Map<String, Object> params) throws BusinessException {  
  500.         Trigger trigger = null;  
  501.         try {  
  502.             trigger = new CronTrigger(UUIDGenerator.getUUID(), params.get("group").toString(), params.get("cronExpression").toString());  
  503.         } catch (ParseException e) {  
  504.             throw new BusinessException("添加cron失败", e);  
  505.         }  
  506.         this.initTrigger(trigger, params);  
  507.         this.addTrigger(trigger);  
  508.     }  
  509.       
  510.     @Override  
  511.     public void saveSimple(Map<String, Object> params) throws BusinessException {  
  512.         String countStr = params.get("repeatCount").toString();  
  513.         int repeatCount = countStr.equals("")?SimpleTrigger.REPEAT_INDEFINITELY:Integer.parseInt(countStr);  
  514.         long repeatInterval = Long.parseLong(params.get("repeatInterval").toString());  
  515.         Trigger trigger = new SimpleTrigger(UUIDGenerator.getUUID(), params.get("group").toString(), repeatCount, repeatInterval);  
  516.         this.initTrigger(trigger, params);  
  517.         this.addTrigger(trigger);  
  518.     }  
  519.       
  520.     @Override  
  521.     public void deleteTriggers(String jobName, String group, String triggerNames) throws BusinessException {  
  522.         String[] trigger = triggerNames.split(",");  
  523.         for(int i=0;i<trigger.length;i++){  
  524.             this.deleteTrigger(trigger[i], group);  
  525.         }  
  526.     }  
  527.       
  528.     @Override  
  529.     public String updateStartOrStop(String triggerName, String group) throws BusinessException {  
  530.         int flag = -1;  
  531.         try {  
  532.             flag = scheduler.getTriggerState(triggerName,group);  
  533.             switch (flag) {  
  534.             case 0 :  
  535.                 scheduler.pauseTrigger(triggerName, group);  
  536.                 flag = 1;  
  537.                 break;  
  538.             case 1 :  
  539.                 scheduler.resumeTrigger(triggerName, group);  
  540.                 flag = 0;  
  541.                 break;  
  542.             }  
  543.         } catch (SchedulerException e) {  
  544.             throw new BusinessException("修改定时状态失败", e);  
  545.         }  
  546.         return "{state:'"+flag+"'}";  
  547.     }  
  548. }  


这种配置就是对quartz的一种简单的使用了,调度任务会在spring启动的时候加载到内存中,按照bjcronTrigger中定义的crontrigger定义的时间按时触发调度任务。 
但是这是quartz使用“内存”方式的一种配置,也比较常见,当然对于不使用spring的项目,也可以单独整合quartz。 
方法也比较简单,可以从quartz的doc中找到配置方式,或者看一下《Quartz Job Scheduling Framework 》(附件中可下载)这本书中的例子。 
但是对于想持久化调度任务的状态,并且灵活调整调度时间的方式来说,上面的内存方式就不能满足要求了,正如本文开始我遇到的情况,需要采用数据库方式集成quartz, 
这部分集成其实在《Quartz Job Scheduling Framework 》中也有较为详细的介绍,当然doc文档中也有, 
但是缺乏和spring集成的实例,我在这里把我在项目中在spring配置quartz数据库存储方式的配置也写一下: 

Xml代码   收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.     xmlns:mvc="http://www.springframework.org/schema/mvc"  
  5.     xmlns:context="http://www.springframework.org/schema/context"  
  6.     xsi:schemaLocation="  
  7.         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
  8.         http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd  
  9.         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">  
  10.       
  11.     <bean name="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">  
  12.         <property name="dataSource">  
  13.             <ref bean="dataSource" />  
  14.         </property>  
  15.         <property name="applicationContextSchedulerContextKey" value="BI-Scheduler" />  
  16.         <property name="configLocation" value="classpath:quartz.properties" />  
  17.     </bean>  
  18. </beans>  

属性说明: 
dataSource:项目中用到的数据源,里面包含了quartz用到的12张数据库表; 
schedulerName:调度器名,我理解主要在调度集群的时候会有用,如果出现多个调度器实例的时候可以用来进行区分,详细看一下《Quartz Job Scheduling Framework 》; 
configLocation:用于指明quartz的配置文件的位置,如果不用spring配置quartz的话,本身quartz是通过一个配置文件进行配置的 
,默认名称是quartz.properties,里面配置的参数在quartz的doc文档中都有介绍,可以调整quartz,我在项目中也用这个文件部分的配置了一些属性,代码如下: 
Xml代码   收藏代码
  1. #============================================================================  
  2. # Configure Main Scheduler Properties    
  3. #============================================================================  
  4.    
  5. org.quartz.scheduler.instanceName = TestScheduler  
  6. org.quartz.scheduler.instanceId = AUTO  
  7.    
  8. #============================================================================  
  9. # Configure ThreadPool    
  10. #============================================================================  
  11.    
  12. orgorg.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool  
  13. org.quartz.threadPool.threadCount = 5  
  14. org.quartz.threadPool.threadPriority = 4  
  15.    
  16. #============================================================================  
  17. # Configure JobStore    
  18. #============================================================================  
  19.    
  20. org.quartz.jobStore.misfireThreshold = 60000  
  21.    
  22. #orgorg.quartz.jobStore.class = org.quartz.simpl.RAMJobStore  
  23.    
  24. orgorg.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX  
  25. ##orgorg.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.oracle.OracleDelegate  
  26. #orgorg.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.PostgreSQLDelegate  
  27. #org.quartz.jobStore.dataSource = myDS  
  28. org.quartz.jobStore.tablePrefix = QRTZ_  
  29. org.quartz.jobStore.isClustered = false  
  30.    
  31. #============================================================================  
  32. # Configure Plugins   
  33. #============================================================================  
  34.    
  35. orgorg.quartz.plugin.triggHistory.class = org.quartz.plugins.history.LoggingJobHistoryPlugin  
  36.   
  37. #orgorg.quartz.plugin.jobInitializer.class = org.quartz.plugins.xml.JobInitializationPlugin  
  38. # init plugin will load jobs.xml as a classpath resource i.e. /jobs.xml if not found on file system  
  39. #org.quartz.plugin.jobInitializer.fileName=jobs.xml  
  40. #org.quartz.plugin.jobInitializer.overWriteExistingJobs = false  
  41. #org.quartz.plugin.jobInitializer.failOnFileNotFound = false  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值