Spring-Batch: How to ensure when a Job is running, it is not allowed to run again at the same time

techanuva picture techanuva · Mar 27, 2013 · Viewed 7.6k times · Source

How to ensure when a Job is running, it is not allowed to run again at the same time?

We have BJ that takes 1 hour to process the feed and populate the temp tables. First step of this BJ is to clear the temp tables and start populating the data from the Main store front tables.

Consider a scenario that when the BJ is started (first time running), if we start the BJ again, it will delete content from temp tables as part of Step one.

So please suggest on how i can hold the second execution till the first is not COMPLETED?

Answer

Michail Nikolaev picture Michail Nikolaev · Mar 27, 2013

You may create custom Tasklet as your first step and use JobExecutionDao in it to find all JobExecutions. If there are more than one running - throw an exception.