15
votes

I have a simple program working with Spring Batch Input reader, Writer. The purpose of the program is to simple read a csv file.

I have set the commit-interval to 5. The csv file had only 5 records but for some reason the Writer was called 3 times although the commit-interval was set to 5. I was expecting that the writer would be called only once based on my understanding that the item reader and processor would read each item line by line and then the writer would process all 5 at once. I guess I am not clear about the impact of commit-interval. Any advise?

1
The reason for my question is I have a million records which I might have to read and pass to the next step using a Java collection.Right now when I try to read from a small file only the last chunk whose number is equal to the the commit-linterval specified is passed to the next step using StepExecution.The previous records don't get passed.How can I ensure that all the records get passed.Will changing the commit-interval help?Or is there another approach? - user5053360
I am using the ExecutionContext and ExecutionContextPromotionListener for this.But only the last chunk which is equal to the commit-interval is set and read in the next step. - user5053360
Please share the configuration file. I want know the type of reader, writer and the processor that you are using. - SyntaX
sure.The reader that we are using is FlatFileItemReader.The processor is ItemProcessor and Writer is ItemWriter.These are classes provided by the API. - user5053360
Please have a look at this site. It may helpful to you. parameshk.blogspot.in/2013/11/… - Paramesh Korrakuti

1 Answers

0
votes

I think you should have something like:

<job id="stepJob">
   <step id="step1">
      <tasklet>
          <chunk reader="inputReader" writer="outputWriter" commit-interval="5"/>
      </tasklet>
    </step>
</job>

The last piece of the example step is the chunk tag where we define what a chunk is for the step. The commit-interval attribute is set at 5 in the example, meaning that no records will be written until 5 records are read and processed.