0

I was going through the documentation of the JdbcBatchItemWriter but noticed that there is no way of specifying the batch-size to use for the jdbcTemplate used by this class. I thought a class that has the name Batch in it would have some mechanism to specify the batch size but looks like this is not the case. I now have the following questions regarding determination of batch-size :

  1. Is the batch-size equivalent to the commit-interval?
  2. If no, does the batch-size get calculated automatically by the framework?

Last but not the least,, is there a way to explicitly specify the batch-size to be used by the jdbcTemplate in the JdbcBatchItemWriter while defining the bean for the JdbcBatchItemWriter class?

Ping
  • 587
  • 5
  • 27

1 Answers1

4

The commit (or batch size) will include all items in the chunk, which is governed by the commit-interval. So for all intents and purposes you can treat commit-interval as batch-size.

One caveat to the statement above: your final chunk may have less items than your commit-interval. Additionally if you filter any records using an ItemProcessor, the count of items passed to your Writer would be lower than your commit-interval. Finally, there are also some custom CompletionPolicy scenarios that may result in a commit with more (or less) items than your commit-interval.

Hope that helps!

Dean Clark
  • 3,770
  • 1
  • 11
  • 26
  • Great and useful insights! Only one aspect of my question remains unanswered i.e, how do I provide a custom batch size to the JdbcBatchItemWriter? My processor returns a List by converting one line from an input file to many output objects. So a single line in the input file is broken down into a `List` of output objects by the processor and sent to the writer. I don't want the commit-interval of the step to govern the DB insert batch size since 1 input row equals tens of thousands of output rows to be written to the database. This is why I need to have a batch size diff from commit interval. – Ping Oct 23 '19 at 19:45
  • From your answer and my research, it is clear that the `JdbcBatchItemWriter` does not allow a custom batch-size. I have accepted your answer and posted a new [related question](https://stackoverflow.com/questions/58534924/spring-batch-write-a-list-to-a-database-table-using-a-custom-batch-size). Please take a look and provide your inputs. – Ping Oct 24 '19 at 05:55