Reputation: 11
I have a spring batch applications with flat file as item reader. This flat contains two different types of records. In the definition of my chunk i have to specify a dynamic commit interval. The application has to commit each time it reads a new type of record.
Example :
1, 'recordType1', 50
1, 'recordType1', 51
1, 'recordType1', 52
COMMIT
2, 'recordType2', 'foo'
COMMIT
1, 'recordType1', 53
COMMIT
2, 'recordType2', 'foo'
COMMIT
1, 'recordType1', 50
1, 'recordType1', 50
1, 'recordType1', 50
1, 'recordType1', 50
COMMIT
2, 'recordType2', 'foo'
2, 'recordType2', 'foo'
2, 'recordType2', 'foo'
2, 'recordType2', 'foo'
COMMIT
How can I do this ?
Upvotes: 0
Views: 1132
Reputation: 2137
the CompletionPolicy is designed to do exactly this use case. That is, you want to commit based on criteria, not just a fixed number. have a look at
org.springframework.batch.repeat.CompletionPolicy
instead of a commit-interval and leverage the isComplete method to evaluate the record and whether it should commit the chunk.
Upvotes: 1