是否有可能找出,如果作业在Spring Batch中重新启动?
我们确实提供了一些Tasklets,但没有spring-batch的重新启动支持,如果重新启动作业,则必须执行我们自己的程序。
在JobRepository,JobOperator,JobExplorer等中找不到任何可能性。
最佳答案
定义具有所需属性的JobExplorer bean
<bean id="jobExplorer"
class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="lobHandler" ref="lobHandler"/>
</bean>
用您的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
}
}
}
没有编译这个,但我希望它能给一个想法