我在使用主题中的配置实现故障转移时遇到问题。我有一个在石英(2.1.7)集群中配置的弹簧批处理作业。在配置文件中,我设置了requestsRecovery = true
,我的石英配置文件是:
org.quartz.scheduler.instanceId=AUTO
org.quartz.scheduler.instanceName = quartzScheduler
org.quartz.scheduler.rmi.export = false
org.quartz.scheduler.rmi.proxy = false
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 10
org.quartz.threadPool.threadPriority = 5
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true
org.quartz.jobStore.useProperties=true
org.quartz.jobStore.isClustered = true
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.tablePrefix = QRPC_
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.scheduler.jmx.export=true
org.quartz.jobStore.clusterCheckinInterval = 20000
我的弹簧配置如下:
<context:component-scan base-package="it.myproject.scheduler" />
<bean name="myJob" class="it.myproject.scheduler.CustomJobDetailFactoryBean">
<property name="jobClass" value="it.myproject.scheduler.SellJob" />
<property name="requestsRecovery" value="true" />
<property name="durability" value="true"/>
</bean>
<bean id="cronTrigger" class="it.myproject.scheduler.CustomCronTriggerFactoryBean">
<property name="jobDetail" ref="myJob"/>
<property name="cronExpression" value="${sched.expression}"/>
</bean>
<bean id="quartzScheduler"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="jobDetails">
<list>
<ref bean="myJob" />
</list>
</property>
<property name="triggers">
<list>
<ref bean="cronTrigger" />
</list>
</property>
<property name="dataSource" ref="myDataSource" />
<property name="transactionManager" ref="transactionManager" />
<property name="schedulerName" value="quartzScheduler"/>
<property name="configLocation" value="file:///quartz.properties" />
<property name="applicationContextSchedulerContextKey" value="applicationContext" />
<property name="overwriteExistingJobs" value="true"/>
<property name="autoStartup" value="true" />
<property name="jobFactory">
<bean class="it.myproject.scheduler.AutowiringSpringBeanJobFactory"/>
</property>
</bean>
工作代码:
import org.springframework.scheduling.quartz.CronTriggerFactoryBean;
import org.springframework.scheduling.quartz.JobDetailAwareTrigger;
public class CustomCronTriggerFactoryBean extends CronTriggerFactoryBean {
@Override
public void afterPropertiesSet() {
super.afterPropertiesSet();
// Remove the JobDetail element
getJobDataMap().remove(JobDetailAwareTrigger.JOB_DETAIL_KEY);
}
}
public class CustomJobDetailFactoryBean extends JobDetailFactoryBean {
private boolean requestsRecovery;
public CustomJobDetailFactoryBean() {
super();
}
@Override
public void afterPropertiesSet() {
super.afterPropertiesSet();
JobDetailImpl jobDetail = (JobDetailImpl) getObject();
jobDetail.setRequestsRecovery(isRequestsRecovery());
}
public boolean isRequestsRecovery() {
return requestsRecovery;
}
public void setRequestsRecovery(boolean requestsRecovery) {
this.requestsRecovery = requestsRecovery;
}
}
public class myJob extends QuartzJobBean {
@Autowired
private MyScheduler task;
@Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
task.runJob();
}
}
我已经在tomcat上的2个独立机器中部署了我的应用程序。并发工作正常,当我启动服务器时,只有1个实例获取锁并且正常工作,但如果我停止已获得锁的机器,则第二台机器不会进行故障转移。如果我只使用一台服务器,则会观察到相同的结果,停止此操作并重新启动不会进行故障转移。
在表job detail
中,requests_recovery
列设置为1.有人可以帮我吗?
答案 0 :(得分:0)
我有同样的问题。我正在做的是,在实例启动时擦除表。特别是,具有自动生成的实例ID的表。但是必须有其他解决方案。