This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

How to implement job timeout

Aug 24th, 2011, 09:15 AM

Hello,

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.

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.