JobBuilderFactory.get(job).incrementer(RunIdIncrementer)的function是什么?

我正在使用Spring-Boot开发一个Spring-Batch项目,一切都顺利进行。 我已经完成了一些春季批量示例(包括一些来自spring.io),但我不确定其中的一些内容是什么,“它只是有效”并不能满足我的需求。

我的spring boot主类实现了CommandLineRunner ,对于这个特定的工作,初始设置看起来像

 @Bean public Job myJob(JobExecutionListenerSupport listener) { return myJobBuilderFactory.get(JOB) .listener(listener) .start(myStep()) .build(); } 

哪个引起了

 java.lang.IllegalStateException: Failed to execute CommandLineRunner at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:809) ~[spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE] at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:790) ~[spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE] at org.springframework.boot.SpringApplication.afterRefresh(SpringApplication.java:777) [spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) [spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191) [spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180) [spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE] at org.bjc.providermodel.maintenance.MaintenanceApplication.main(MaintenanceApplication.java:20) [classes/:?] Caused by: org.springframework.batch.core.repository.JobExecutionAlreadyRunningException: A job execution for this job is already running: JobInstance: id=99, version=0, Job=[myJob] 

为什么要将上面的bean更改为

 @Bean public Job myJob(JobExecutionListenerSupport listener) { return myJobBuilderFactory.get(JOB) .incrementer(new RunIdIncrementer()) .listener(listener) .start(myStep()) .build(); } 

让一切顺利吗? 我RunIdIncrementer阅读RunIdIncrementer的文档,并在这里阅读了一些内容。 从我可以告诉它需要这个增量器来跟踪正在运行的特定工作集来做“东西”,但不确定究竟是什么东西。 Spring-Boot抽象让我很难知道这里发生了什么

这不是“引导事物”,而是“批量事物”。 Spring Batch有一个规则,即JobInstance只能运行一次才能完成。 这意味着对于识别作业参数的每个组合,您只能有一个JobExecution导致COMPLETERunIdIncrementer会在参数列表中附加一个附加的唯一参数,以便生成的组合是唯一的……每次使用相同的识别参数组合运行作业时,都会为您提供一个新的JobInstance

RunIdIncrementer实际上只是RunIdIncrementer一个特例,您可以在我们的文档中阅读更多内容: http : JobParametersIncrementer