javajsr352jberet

JSR352 How to prevent same job to run twice?


I am using JBeret on WildFly.

Is there a way to prevent a Job from running twice at the same time?

I.e. a Job is scheduled to run every hour. If the Job runs longer than an hour, I dont want it to run twice at the same time, meaning the second instance should fail or otherwise reject to be started.

Is there a way do declare that kind of behavoir in the Batch xml files?


Solution

  • No, I don't see any way to do that in job xml. Your application code can check if there is any running job executions for the same job name, and then decides to start a new execution or not. For scheduled executions, you can add such a check in the scheduled task to check, and if there is one, the task can just bail out.