Spring Batch:如何确定作业是否重新启动 [英] Spring Batch: How to find out if job is restarted
本文介绍了Spring Batch:如何确定作业是否重新启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有可能找到,如果在Spring Batch中重新启动作业?
Is there any possibility to find out, If a job is restarted in Spring Batch?
我们确实提供了一些没有从spring-batch重启支持的Tasklet,并且如果重新启动了作业,则必须实现我们自己的程序。
We do provide some Tasklets without restart-support from spring-batch and has to implement our own proceeding, if job is restarted.
在JobRepository,JobOperator,JobExplorer等中找不到任何可能。
Can't find any possibility in JobRepository, JobOperator, JobExplorer, etc.
推荐答案
使用必需属性定义JobExplorer bean
Define a JobExplorer bean with required properties
<bean id="jobExplorer"
class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="lobHandler" ref="lobHandler"/>
</bean>
用你的jobName查询
Query it with your jobName
List<JobInstance> jobInstances= jobExplorer.getJobInstances(jobName);
for (JobInstance jobInstance : jobInstances) {
List<JobExecution> jobExecutions = jobExplorer.getJobExecutions(jobInstance);
for (JobExecution jobExecution : jobExecutions) {
if (jobExecution.getExitStatus().equals(ExitStatus.COMPLETED)) {
//You found a completed job, possible candidate for a restart
//You may check if the job is restarted comparing jobParameters
JobParameters jobParameters = jobInstance.getParameters();
//Check your running job if it has the same jobParameters
}
}
}
没有编译这个,但我希望它能给出一个想法
Did not compile this but I hope it gives an idea
这篇关于Spring Batch:如何确定作业是否重新启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文