[英]Running a spring batch job multiple times
I have created a spring batch job with spring boot using below tutorial: 我使用以下教程使用spring boot创建了spring batch作业:
https://spring.io/guides/gs/batch-processing/
The job is reading a file and writing to a database as expected. 作业正在按预期方式读取文件并写入数据库。
However, now I have a use case to run this job multiple times. 但是,现在我有一个用例可以多次运行此作业。
I have an ArrayList
of parameters. 我有一个ArrayList
参数。
What changes should I do to the job so that I can run the job the number of times the size of my ArrayList
? 我应该对作业进行哪些更改,以便可以将作业运行到ArrayList
大小的倍数上?
You can kickstart your batch job manually like this 您可以像这样手动启动批处理作业
@Component
Class Someclass{
...............
@Autowired
private JobLauncher jobLauncher;
@Autowired
private Job job;
public void someFunction(){
jobLauncher.run(job, new JobParameters());
}
}
Only thing is you cannot restart a batch job if it is already completed, It throws an error saying the status is COMPLETED. 唯一的事情是,如果批处理作业已经完成,则无法重新启动它,并且会引发错误,指出状态为COMPLETED。 For this to work you have to set allowStartIfComplete
property to true. 为此,您必须将allowStartIfComplete
属性设置为true。 This has to be done in your batch step configuration, something like this 这必须在您的批处理步骤配置中完成,就像这样
stepBuilderFactory.get("step1")
.<Person, Person> chunk(10)
.reader(reader())
.processor(processor())
.writer(writer())
.allowStartIfComplete(true)
.build();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.