I have created a spring batch job with spring boot using below tutorial:
我使用以下教程创建了一个带有spring boot的spring批处理作业:
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大小的作业次数?
1 个解决方案
#1
3
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. For this to work you have to set allowStartIfComplete
property to true. This has to be done in your batch step configuration, something like this
唯一的问题是,如果批处理作业已经完成,则无法重新启动批处理作业,它会抛出一个错误,指出状态为COMPLETED。为此,您必须将allowStartIfComplete属性设置为true。这必须在您的批处理步骤配置中完成,类似这样
stepBuilderFactory.get("step1")
.<Person, Person> chunk(10)
.reader(reader())
.processor(processor())
.writer(writer())
.allowStartIfComplete(true)
.build();
#1
3
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. For this to work you have to set allowStartIfComplete
property to true. This has to be done in your batch step configuration, something like this
唯一的问题是,如果批处理作业已经完成,则无法重新启动批处理作业,它会抛出一个错误,指出状态为COMPLETED。为此,您必须将allowStartIfComplete属性设置为true。这必须在您的批处理步骤配置中完成,类似这样
stepBuilderFactory.get("step1")
.<Person, Person> chunk(10)
.reader(reader())
.processor(processor())
.writer(writer())
.allowStartIfComplete(true)
.build();