javajdbcspring-batchbatch-updatesitemwriter

How does the JdbcBatchItemWriter decide the batch size?


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?


Solution

  • 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!