Aug 24th, 2011, 08:15 AM
How to implement job timeout
I'm looking for ideas about the best way to put a timeout parameter around an entire job. I would also consider a similar parameter at the step level. In short, I would like to be able to specify that a Spring Batch job can run for 30 minutes max. If, after 30 minutes the job still running, it would be marked FAIL and terminated. At which point, the scheduler would be free to start future invocations of the job at the normal schedule. I need some sort of callback that is triggered after a fix internal and sees if the the job is still running. If it is, it should terminate it. Any ideas on how I can elegantly define a job (or steps) that could be configured with a timeout parameter? I'm aware of the transaction timeout parameter that is available around steps. However, I'm using web services and there is no formal transaction around these calls so this parameter is of little use to me.
Any ideas? I figure spring or spring batch must have some hooks that will allow for an elegant solution.
Aug 30th, 2011, 03:01 AM
Spring Batch Admin has metrics for StepExecution time and the sample shows how to use a StepExecutionServiceLevelMonitor to generate a JMX notification if a step exceeds a timeout. Turning that into a signal that you can react to locally or remotely is relatively trivial.