我正在使用 SimpleTrigger 安排一个应该无限期运行的作业(重复计数-1)。
我正在使用 JDBC 存储将作业状态持久保存在数据库中。
但是触发器会触发一些时间间隔(在我的情况下总是 8)并进入 BLOCKED 状态。具体来说,QRTZ_TRIGGERS 表中 TRIGGERS_STATE 的值将被更改为 BLOCKED。注意我的 Quartx 表的前缀是 QRTZ_ 下面是我的 Job Trigger 信息。
重复计数:-1,重复间隔:6 秒,启动延迟:10 秒
MY石英配置:
#===============================================================
#Configure ThreadPool
#===============================================================
org.quartz.threadPool.class=org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 10
org.quartz.threadPool.threadPriority = 5
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true
#===============================================================
#Configure JobStore
#===============================================================
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.misfireThreshold = 60000
org.quartz.jobStore.maxMisfiresToHandleAtATime=20
# Flag to turn off to ignore all misfires
scheduler.ignoreMisfire=no
# Configuring JDBCJobStore with the Table Prefix
org.quartz.jobStore.tablePrefix = QRTZ_
# Using DriverDelegate
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.oracle.OracleDelegate
org.quartz.jobStore.useProperties = false
调度程序类:
public static void scheduleJob(Class<? extends Job> job,JobDataMap dataMap)
{
Scheduler scheduler = schedulerFactoryBean.getScheduler();
try
{
JobDetail jobDetail = newJob(job)
.withIdentity(job.getSimpleName()+"_"+DateUtil.getSystemDate(), job.getSimpleName() + "_group")
.storeDurably()
.usingJobData(dataMap)
.requestRecovery()
.build();
SimpleTrigger trigger = (SimpleTrigger) newTrigger()
.withIdentity(job.getSimpleName() + "_trigger_"+DateUtil.getSystemDateWithMs(), job.getSimpleName() + "_trigger_group")
.startNow()
.withSchedule(simpleSchedule().repeatSecondlyForever(10).withMisfireHandlingInstructionFireNow())
.build();
scheduler.scheduleJob(jobDetail, trigger);
//logger.debug(scheduler.getMetaData().toString());
scheduler.start();
}
catch (SchedulerException e)
{
e.printStackTrace();
throw new SchedulerException("", e);
}
}
工作类别:
@PersistJobDataAfterExecution
public class MyJob Implements Job
{
private SessionFactory sessionFactory;
@Override
public void execute(JobExecutionContext context) throws JobExecutionException
{
getBeansFromContext(context);
Session session = sessionFactory.openSession(); // Hibernate Session Factory
// to do some DB opetations
}
private void getBeansFromContext(JobExecutionContext context) throws SchedulerException
{
ApplicationContext applicationContext = (ApplicationContext)context.getScheduler().getContext().get("applicationContext");
this.sessionFactory=applicationContext.getBean(SessionFactory.class);
}
}
Quartz 调度器工厂的 Spring bean 配置。
<beans:bean id="schedulerFactoryBean"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<beans:property name="jobFactory">
<beans:bean class="org.springframework.scheduling.quartz.SpringBeanJobFactory"></beans:bean>
</beans:property>
<beans:property name="dataSource" ref="dataSource" />
<beans:property name="transactionManager" ref="txManager" />
<beans:property name="configLocation"
value="resources/scheduler/Scheduler.properties" />
<beans:property name="applicationContextSchedulerContextKey"
value="applicationContext" />
<beans:property name="autoStartup" value="true" />
</beans:bean>
<beans:bean id="taskExecutor"
class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor"
p:corePoolSize="5" p:maxPoolSize="10" p:queueCapacity="100"
p:waitForTasksToCompleteOnShutdown="true" />
非常感谢任何帮助。提前致谢