spring整合quartz2定时器启动报:batch acquisition of 0 triggers

 

DEBUG org.quartz.core.QuartzSchedulerThread - batch acquisition of 0 triggers

这是条日志输出,输出这样的内容表示目前没有要执行的trigger,这不是错,而且此时任务不执行。

如果要执行,看配置的cron时间,让它配置成在当前一会可执行的时间就行了。


DEBUG org.quartz.core.QuartzSchedulerThread - batch acquisition of 0 triggerseclips

e DEBUG模式下一直打印类似以上提示日志,非debug下却没有

解决方法: log4j.properties : log4j.logger.org.quartz=INFO :log4j.logger.org.quartz 下只有info级别以上的才能打印日志


已标记关键词 清除标记
spring配置如图:![图片说明](https://img-ask.csdn.net/upload/201708/03/1501752585_694066.png) RunQuartz实现InitializingBean进行初始化并注入schedulerFactoryBean,如果scope不设置为protorype就会错如图:![图片说明](https://img-ask.csdn.net/upload/201708/03/1501752563_984249.png) 将scope设为protorype后定时任务就一直不执行,打印batch acquisition of 0 triggers。 RunQuartz代码如下: public class RunQuartz implements InitializingBean{ private SchedulerFactoryBean schedulerFactoryBean; @Override public void afterPropertiesSet() throws Exception { System.out.println("++++++++++++++init方法"); List<ScheduleJob> jobList = new ArrayList<>(); for (int i = 0; i < 5; i++) { ScheduleJob job = new ScheduleJob(); job.setJobId("10001" + i); job.setJobName("data_import" + i); job.setJobGroup("dataWork"); job.setCronExpression("*/5 * * * * ?"); jobList.add(job); } Scheduler scheduler = schedulerFactoryBean.getScheduler(); for (ScheduleJob job : jobList) { TriggerKey triggerKey = TriggerKey.triggerKey(job.getJobName(), job.getJobGroup()); //获取trigger,即在spring配置文件中定义的 bean id="myTrigger" CronTrigger trigger = null; try { trigger = (CronTrigger) scheduler.getTrigger(triggerKey); } catch (SchedulerException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //不存在,创建一个 if (null == trigger) { JobDetail jobDetail = JobBuilder.newJob(QuartzJobFactory.class) .withIdentity(job.getJobName(), job.getJobGroup()).build(); jobDetail.getJobDataMap().put("scheduleJob", job); //表达式调度构建器 CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(job.getCronExpression()); //按新的cronExpression表达式构建一个新的trigger trigger = TriggerBuilder.newTrigger().withIdentity(job.getJobName(), job.getJobGroup()).withSchedule(scheduleBuilder).build(); try { scheduler.scheduleJob(jobDetail, trigger); } catch (SchedulerException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { // Trigger已存在,那么更新相应的定时设置 //表达式调度构建器 CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(job.getCronExpression()); //按新的cronExpression表达式重新构建trigger trigger = trigger.getTriggerBuilder().withIdentity(triggerKey) .withSchedule(scheduleBuilder).build(); //按新的trigger重新设置job执行 try { scheduler.rescheduleJob(triggerKey, trigger); } catch (SchedulerException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } public SchedulerFactoryBean getSchedulerFactoryBean() { return schedulerFactoryBean; } public void setSchedulerFactoryBean(SchedulerFactoryBean schedulerFactoryBean) { this.schedulerFactoryBean = schedulerFactoryBean; } }
相关配置文件如下 (1)web.xml中相关配置 <!-- qutarz loader configuration --> <servlet> <servlet-name>QuartzInitializer</servlet-name> <servlet-class> org.quartz.ee.servlet.QuartzInitializerServlet </servlet-class> <init-param> <param-name>shutdown-on-unload</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>config-file</param-name> <param-value>quartz.properties</param-value> </init-param> <load-on-startup>2</load-on-startup> </servlet> (2)quartz.properties文件内容 # # Configure Main Scheduler Properties # org.quartz.scheduler.instanceName = DataTransmit org.quartz.scheduler.instanceId = one # # Configure ThreadPool # org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool org.quartz.threadPool.threadCount = 5 org.quartz.threadPool.threadPriority = 4 # # Configure JobStore # org.quartz.jobStore.misfireThreshold = 5000 org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore # =========================================================================== # Configure SchedulerPlugins =============================================== # =========================================================================== org.quartz.plugin.triggHistory.class =org.quartz.plugins.history.LoggingTriggerHistoryPlugin org.quartz.plugin.triggHistory.triggerFiredMessage = Trigger{1}.{0}firedjob{6}.{5}at:{4,date,HH:mm:ssMM/dd/yyyy} org.quartz.plugin.triggHistory.triggerCompleteMessage = Trigger{1}.{0}completedfiringjob{6}.{5}at{4,date,HH:mm:ssMM/dd/yyyy}withresultingtriggerinstructioncode:{9} org.quartz.plugin.jobInitializer.class = org.quartz.plugins.xml.JobInitializationPlugin org.quartz.plugin.jobInitializer.fileName =/quartz_reminder.xml org.quartz.plugin.jobInitializer.overWriteExistingJobs = false org.quartz.plugin.jobInitializer.failOnFileNotFound = true org.quartz.plugin.shutdownhook.class = org.quartz.plugins.management.ShutdownHookPlugin org.quartz.plugin.shutdownhook.cleanShutdown = true (3)quartz_reminder.xml文件内容 <?xml version="1.0" encoding="UTF-8"?> <quartz> <!-- 每日更新表情计数 --> <job> <job-detail> <name>jobDetail4Day</name> <group>DEFAULT</group> <job-class>com.cycnet.schedule.UpdateFellingCount</job-class> </job-detail> <trigger> <cron> <name>trigger4Day</name> <group>DEFAULT</group> <job-name>updatePerDay</job-name> <job-group>DEFAULT</job-group> <!-- 每天晚上0点触发此任务 --> <cron-expression> 0 0 23 * * ? </cron-expression> </cron> </trigger> </job> </quartz> !!遇到问题 : 当我改变 我的操作系统 的日期时 会在一个我不期望的时间(不是 0 0 23 * * ? 这个表达式表述的时间内) 调用 UpdateFellingCount(Job导出类) 的excute方法 请各位帮忙看下是什么原因,是不是我的配置文件有问题 谢谢 [b]问题补充:[/b] 相关配置文件如下 (1)web.xml中相关配置 <!-- qutarz loader configuration --> <servlet> <servlet-name>QuartzInitializer</servlet-name> <servlet-class> org.quartz.ee.servlet.QuartzInitializerServlet </servlet-class> <init-param> <param-name>shutdown-on-unload</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>config-file</param-name> <param-value>quartz.properties</param-value> </init-param> <load-on-startup>2</load-on-startup> </servlet> (2)quartz.properties文件内容 # # Configure Main Scheduler Properties # org.quartz.scheduler.instanceName = DataTransmit org.quartz.scheduler.instanceId = one # # Configure ThreadPool # org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool org.quartz.threadPool.threadCount = 5 org.quartz.threadPool.threadPriority = 4 # # Configure JobStore # org.quartz.jobStore.misfireThreshold = 5000 org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore # =========================================================================== # Configure SchedulerPlugins =============================================== # =========================================================================== org.quartz.plugin.triggHistory.class =org.quartz.plugins.history.LoggingTriggerHistoryPlugin org.quartz.plugin.triggHistory.triggerFiredMessage = Trigger{1}.{0}firedjob{6}.{5}at:{4,date,HH:mm:ssMM/dd/yyyy} org.quartz.plugin.triggHistory.triggerCompleteMessage = Trigger{1}.{0}completedfiringjob{6}.{5}at{4,date,HH:mm:ssMM/dd/yyyy}withresultingtriggerinstructioncode:{9} org.quartz.plugin.jobInitializer.class = org.quartz.plugins.xml.JobInitializationPlugin org.quartz.plugin.jobInitializer.fileName =/quartz_reminder.xml org.quartz.plugin.jobInitializer.overWriteExistingJobs = false org.quartz.plugin.jobInitializer.failOnFileNotFound = true org.quartz.plugin.shutdownhook.class = org.quartz.plugins.management.ShutdownHookPlugin org.quartz.plugin.shutdownhook.cleanShutdown = true (3)quartz_reminder.xml文件内容 <?xml version="1.0" encoding="UTF-8"?> <quartz> <!-- 每日更新表情计数 --> <job> <job-detail> <name>jobDetail4Day</name> <group>DEFAULT</group> <job-class>com.cycnet.schedule.UpdateFellingCount</job-class> </job-detail> <trigger> <cron> <name>trigger4Day</name> <group>DEFAULT</group> <job-name>updatePerDay</job-name> <job-group>DEFAULT</job-group> <!-- 每天晚上0点触发此任务 --> <cron-expression> 0 0 23 * * ? </cron-expression> </cron> </trigger> </job> </quartz> !!遇到问题 : 当我改变 我的操作系统 的日期时 会在一个我不期望的时间(不是 0 0 23 * * ? 这个表达式表述的时间内) 调用 UpdateFellingCount(Job导出类) 的excute方法 请各位帮忙看下是什么原因,是不是我的配置文件有问题 谢谢 补充:quartz版本是1.6.0 [b]问题补充:[/b] 不改变是正常的吗? pan_java (初级程序员) 2009-07-15 不太清楚,因为程序刚写完,应用还没有在晚上运行过 重新启动一下服务器 rain2005 (高级程序员) 2009-07-15 重启后无果 再问一下,怎么回复 答案啊? javaeye做的不是很人性化, :( [b]问题补充:[/b] 遇到了更奇怪的问题 我设置了每10秒执行一次(0/10 * * * * ?) 可以正常执行, 我修改为每分钟的20秒时执行一次(20 * * * * ?) 然后重启服务,还是每10秒执行一次, 更改excute方法 System.out.println("in the UpdateFellingCount !!! " + new Date()); (更改前) ------>>>>>>>(更改后) System.out.println("in the UpdateFellingCount !!! " + new Date() + "!!!!"); 然后重新部署应用,清空tomcat的work目录,重启Eclipse, 结果还是每10秒执行一次,console内容如下: in the UpdateFellingCount !!! Wed Jul 15 15:35:00 CST 2009 in the UpdateFellingCount !!! Wed Jul 15 15:35:10 CST 2009 in the UpdateFellingCount !!! Wed Jul 15 15:35:20 CST 2009 in the UpdateFellingCount !!! Wed Jul 15 15:35:30 CST 2009 in the UpdateFellingCount !!! Wed Jul 15 15:35:40 CST 2009 in the UpdateFellingCount !!! Wed Jul 15 15:35:50 CST 2009 in the UpdateFellingCount !!! Wed Jul 15 15:36:00 CST 2009 in the UpdateFellingCount !!! Wed Jul 15 15:36:10 CST 2009 !!!!!!!
©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客 返回首页