obiyadi
obiyadi

Reputation: 43

Stop spring batch in failure

Bonjour,

I need to stop a running spring batch with Failure status if, in my reader, a test return true. How can I do this ? I actually use System.exit(-1), but I think that spring batch has his own way to stop running batch with different status.

here is the function in my reader from which I want to stop the batch:

private List<Test> getListTest() throws Exception {
    ...
            if (stop) {
            logger.error("Stop running batch");
            System.exit(-1);
            return null;
            }
    ...
}

Merci et bonne journée

Upvotes: 1

Views: 3180

Answers (1)

DevG
DevG

Reputation: 494

There are two ways to fail a spring batch job.

  1. Simply throw an exception inside reader and spring batch will automatically stop the job with failed status .
  2. You can use joboperator.stop() method to stop any running job . This method will send a signal to stop Job ,but job will be stopped only after the transaction gets completed .

Upvotes: 2

Related Questions