Announcement Announcement Module
No announcement yet.
detecting already running job in spring batch Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • detecting already running job in spring batch

    Hi friends,

    I have a requirement to start my job only when any of the instances of the job aren't running .

    How can I achieve this in spring batch framework ?

  • #2
    Hi you can achieve this through extending the SimpleJobLauncher and implementing a job lock within the public JobExecution run(Job job, JobParameters jobParameters) method. You need to specify the job launcher in the batch overrides file in order for Batch to use it.

    In our case we used a distributed cache lock mechanism (terracotta) where we put the job name into the cache and lock it. We unlock it in the finally block of the try..catch..finally we have wrapping the logic in the overridden run() method.

    We didn't end up looking at the job repository because we don't always trust the statuses we're seeing there.


    • #3
      We actually provide in Spring Batch Admin, a JobLauncherSynchronizer implementation that wraps a JobLauncher to prevent that scenario from occurring. You can read more about it here:


      • #4
        The distinction is that a launchable job is defined and configured in the application itself, whereas a non-launchable job is detected as state left by the execution of a job in another process.
        Last edited by Hodge25; Dec 25th, 2013, 09:44 PM.