简体   繁体   English

Spring Batch Job依赖

[英]Spring Batch Job dependency

I am new to Spring Batch. 我是Spring Batch的新手。 I have a requirement to schedule multiple jobs where one job is dependent on completion of other job. 我需要安排多个作业,其中一个作业取决于其他作业的完成。 In Spring Batch I found that it is very easy to put step dependency. 在Spring Batch中,我发现放置步骤依赖性非常容易。 Is there any way to make one job dependent on other job? 有什么方法可以使一项工作依赖于另一项工作?

You could use a JobExecutionListener.afterJob and run the other job based on the outcome of the first. 您可以使用JobExecutionListener.afterJob并根据第一个作业的结果运行另一个作业。 See the docs for more details. 有关更多详细信息,请参阅文档

But it might make more sense to configure a new job that encompasses all these steps and re-uses the existing steps in that job. 但是配置包含所有这些步骤的新作业并重新使用该作业中的现有步骤可能更有意义。

Spring Batch does not provide a way to have dependency between jobs. Spring Batch没有提供在作业之间具有依赖关系的方法。 However ideal way to achieve this is how you are invoking the jobs. 但是,实现此目标的理想方法是调用工作的方式。 This can be easily achieved using Quartz scheduler. 使用Quartz调度程序可以轻松实现这一点。

Or can be done like this. 或者可以这样做。

ApplicationContext context = new ClassPathXmlApplicationContext(config);
JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
Job job1 = (Job) context.getBean("testJob");
Job job2 = (Job) context.getBean("testJob2");


JobExecution execution1 = jobLauncher.run(job1, new JobParameters());
System.out.println("Exit Status : " + execution1.getStatus());
if(execution1.getStatus()==0){
     JobExecution execution2 = jobLauncher.run(job2, new JobParameters());
     System.out.println("Exit Status : " + execution2.getStatus());
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM