- What didn’t I find? Where does this "run.id" come from
Jobparameters
This is just a parameter that you pass to jobParameters. Usually, a different run.id (conditional name) is used for each instance, since the structure does not have the ability to find out what changes in JobParameters make it the "next" instance of the job.
You can pass this "run.id" to jobParameters as:
new JobParametersBuilder().addLong("run.id", 1L).toJobParameters()
JobParametersIncrementer look at the JobParametersIncrementer documentation for more details.
- How to pass a common identifier between a step listener and a reader, so that each thread has its own set of records for processing
Not
This is a rather dangerous route, since many Step participants (for example, readers and writers) have a state, and if the state is not separated by a thread, then these components cannot be used in a multi-threaded step. In particular, most of Spring Batch's ready-made readers and writers are not designed for multi-threaded use.
Markup
I would recommend using Partitioning . This is much simpler than it sounds, and you can use multiple threads for it . Take a look at examples of batch jobs that use partitioning that comes from "Spring batch samples" to:
show multithreaded step execution using SPI PartitionHandler. The example uses TaskExecutorPartitionHandler to distribute the work of reading certain files across multiple threads with a single execution step for each thread. Key components are PartitionStep and MultiResourcePartitioner, which are responsible for sharing work. Please note that readers and writers at the stage, which is divided into sections, have a power-law scope, so that their state does not receive general access to the threads of execution.
source share