为什么Quartz作业停止触发并且触发器的状态从WAITING变为ERROR?

时间:2015-12-22 13:09:49

标签: java spring triggers quartz-scheduler jobs

问题说明:

我有一个Java服务,它动态创建石英作业,触发器并将这些细节保存到Quartz相关表中。

如果我强行停止tomcat服务器,则“Qrtz_triggers”的触发状态字段变为ERROR。 它永远不会执行。

如果我将状态更改为WAITING,那么它将开始正确执行。

Quartz配置:

db_select --> stand for $this->db->select
db_group --> stand for $this->db->group_by
db_get --> stand for $this->db->get

用于创建Quartz Job和Quartz Trigger的Java类

<bean id="schedulerFactoryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" lazy-init="false">
              <property name="schedulerName" value="IPASScheduler"/>
              <property name="autoStartup" value="true" />
              <property name="applicationContextSchedulerContextKey" value="applicationContext" />
              <property name="waitForJobsToCompleteOnShutdown" value="true" />
              <property name="overwriteExistingJobs" value="true" />
              <property name="dataSource">
                     <ref bean="dataSource" />
              </property>
              <property name="transactionManager">
                     <ref bean="transactionManager" />
              </property>
              <property name="jobFactory" ref="jobFactoryBean"/>
              <property name="quartzProperties">
                     <props>
                           <prop key="org.quartz.jobStore.misfireThreshold">6000000</prop>
                           <prop key="org.quartz.jobStore.driverDelegateClass">org.quartz.impl.jdbcjobstore.oracle.OracleDelegate</prop>
                           <prop key="org.quartz.jobStore.isClustered">true</prop>
                           <prop key="org.quartz.jobStore.clusterCheckinInterval">20000</prop>
                           <prop key="org.quartz.jobStore.class">org.quartz.impl.jdbcjobstore.JobStoreTX</prop>
                           <prop key="org.quartz.scheduler.instanceName">IPASClusteredScheduler</prop>
                           <prop key="org.quartz.scheduler.instanceId">AUTO</prop>
                           <prop key="org.quartz.scheduler.jmx.export">true</prop>
                           <prop key="org.quartz.jobStore.selectWithLockSQL">SELECT * FROM QRTZ_LOCKS WHERE LOCK_NAME = ?</prop>
                           <prop key="org.quartz.threadPool.threadCount">10</prop>
                           <prop key="org.quartz.threadPool.threadPriority">5</prop>
<!--                        <prop key="org.quartz.jobStore.dontSetAutoCommitFalse">true</prop> -->
<!--                        <prop key="org.quartz.scheduler.wrapJobExecutionInUserTransaction">false</prop>  -->
<!--                        <prop key="org.quartz.jobStore.useProperties">false</prop>                        -->
                     </props>
              </property>                
       </bean> 

作业:

//creating Quartz job 
JobDetail job = JobBuilder.newJob(ReportRunnerJob.class).withIdentity(jobName, "MY_REPORTING").build();



//Creating trigger            
CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(triggerName, "MY_REPORTING").withSchedule(CronScheduleBuilder.cronSchedule("0/10 * * * * ?")).withMisfireHandlingInstructionFireAndProceed()).build();

                     Scheduler scheduler = schedulerFactoryBean.getScheduler();
                     scheduler.scheduleJob(job, trigger);
                     scheduler.start();
                  //   Thread.sleep(1000L);
                  //   scheduler.shutdown(true);

1 个答案:

答案 0 :(得分:0)

我建议你为石英启用DEBUG日志级别。

我怀疑,当你强行停止tomcat时。 您的石英触发器会尝试加载ReportRunnerJob类,在这些停止时刻,它会失败并将触发器状态更新为&#34; ERROR&#34;