2012-07-27 108 views
1

是否有任何可能發現,如果一個作業在Spring Batch中重新啓動?春季批次:如何找出作業是否重新啓動

我們確實提供了一些無需從spring-batch重新啓動支持的Tasklet,並且如果重新啓動作業,必須執行我們自己的過程。

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

回答

5

定義JobExplorer豆要求特性

<bean id="jobExplorer" 
class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean"> 
<property name="dataSource" ref="dataSource"/> 
<property name="lobHandler" ref="lobHandler"/> 
</bean> 

查詢它與你的工作名

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 
     } 
    } 
} 

沒有編譯這一點,但我希望它給一個想法

+0

在我看來,這是一種安靜的方式。順便說一下:我是否認爲只有未完成的JobInstances可以重新啓動?謝謝你的幫助! – maxhax 2012-07-30 08:14:31

0

潛在的,你可以找到在春天批次的數據庫表信息,不記得確切的表的名字,但你可以計算出很快,因爲只有幾張桌子。我想有一些關於重新啓動的信息。

+0

寧願採用其他方式,不需要直接訪問數據庫 – maxhax 2012-07-27 10:28:25

1

使用jobExplorer是另一種方式執行以下命令:

jobExplorer.getJobExecutions(jobExplorer.getJobInstance(currentJobExecution.getJobInstance().getId())).size() > 1; 

該語句驗證是否存在另一個相同作業(相同ID)的執行。在具有最小控制的環境中,不存在其他執行不是失敗或停止執行的可能性。