Spring Batch: CommandLineJobRunner to Run Multiple Jobs

Sometimes this requirement may jump at you: “I still want to have them as several jobs, but I want no operational overhead, and need to run them in sequence via a single launch…”.

So if you were using CommandLineJobRunner to launch these jobs, it would only be natural to aggregate those calls under your own e.g. “CommandLineMultipleJobRunner” that just delegates its calls to “CommandLineJobRunner” for each job in a list..

The only caveat is the default SystemExiter which is set to JvmSystemExiter, which makes it imposible to make more than one launch using a “CommandLineJobRunner”, since “JvmSystemExiter” does:

public void exit(int status) {

Fortunately, there is a static accessor to override this behavior:

// disabling a default "JvmSystemExiter" to be able to run several times
CommandLineJobRunner.presetSystemExiter( new SystemExiter() { public void exit( int status ) {} } );

Now, call “CommandLineJobRunner.main( String[] args )” as many times as you’d like.

If you have a choice, think about creating a single multi step job instead, but if you don’t have a luxury, “CommandLineMultipleJobRunner” should now be not all that hard to implement.

Batch Away! :)


  1. Hi,

    I am interested in sending you the free eBook PDF of Spring Batch in Action. This book is still in publication. Please let me know if you are interested?

    Best, Candace

  2. @Candace,

    Sure, let me know if you need any help on the book. I talked to Paul King ( Groovy Masta ) back in October 2010, he said that this book needed a couple of chapters, which back then were not even started.

    You can use a “Contact” link on this blog to “get to me” :)


  3. Sandeep Jindal

    This is really great. Thanks

tell me something...
  1. (required)
  2. (valid email - optional)
  3. Captcha
  4. (required)