Adrian Shum
Adrian Shum

Reputation: 40036

Anyway to execute logic after chunk but before commit

In Spring Batch, what is the proper way to perform some kind of logic after the chunk logic is done, but before commit/rollback?

afterChunk is currently triggered after transaction. What if I want to do some kind of cleanup before commit? (e.g. cleanup some temp records inserted in beforeChunk).

One workaround I can think of is by making use a CompositeWriter, and have the extra logic being another writer. However it is going to make maintenance difficult, because I cannot make up a shared parent step configuration that contains that "extra logic".

Upvotes: 0

Views: 2344

Answers (1)

Luca Basso Ricci
Luca Basso Ricci

Reputation: 18403

You can use ItemWriteListener.afterWrite()

Called after ItemWriter.write(java.util.List) This will be called before any transaction is committed, and before ChunkListener.afterChunk(ChunkContext)

Upvotes: 1

Related Questions