Book Image

Mastering Spring Application Development

By : Anjana Mankale
Book Image

Mastering Spring Application Development

By: Anjana Mankale

Overview of this book

Table of Contents (19 chapters)
Mastering Spring Application Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Intercepting a Spring Batch job with listeners


Spring Batch comes with listeners. They intercept the job execution to perform certain tasks. StepListener is a super class for the following mentioned listeners:

  • SkipListener: One of the most common use cases for SkipListener is to log out a skipped item so that another batch process, or even human process, can be used to evaluate and fix the issue leading to the skip. Because there are many cases in which the original transaction may be rolled back, Spring Batch makes two guarantees:

    • The appropriate skip method (depending on when the error happened) will only be called once per item.

    • The SkipListener will always be called just before the transaction is committed. This is to ensure that any transactional resources called by the listener are not rolled back by a failure within ItemWriter.

  • ChunkListener: These listeners can be configured with a step, and if the step is of the type chunk-styled step, this will have both ItemReader and ItemWriter...