Spring Batch:如何确定作业是否重新启动

max*_*der 1 java restart spring-batch

有没有可能找到,如果在Spring Batch中重新启动作业?

如果重新启动作业,我们确实提供了一些没有从spring-batch重新启动支持的Tasklet,并且必须实现我们自己的程序.

在JobRepository,JobOperator,JobExplorer等中找不到任何可能性.

Ser*_*uşu 7

使用必需的属性定义JobExplorer bean

<bean id="jobExplorer"
class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="lobHandler" ref="lobHandler"/>
</bean>
Run Code Online (Sandbox Code Playgroud)

使用您的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 
        }
     }
}
Run Code Online (Sandbox Code Playgroud)

没有编译这个,但我希望它给出一个想法