Reputation: 429
I'm struggling with the following problem. I have a single Spring Batch Job which is executed every 10 minutes via a @Scheduled
method. If a job execution fails, I need to terminate the schedule. I know how to do this either by
a) calling ScheduledAnnotationBeanPostProcessor::postProcessBeforeDestruction()
or
b) making a custom ThreadPoolTaskScheduler
, storing ScheduledFutures
and then cancel()ing them,
but in both cases the problem is the same : tons of Spring Batch TransactionSystemExceptions
because it can no longer commit metadata. And despite not having any more @Scheduled
tasks to run, the application doesn't terminate...
Any ideas?
Cheers!
Upvotes: 0
Views: 564
Reputation: 31600
If guess (from the tags) you are using Spring Boot. So in that case, please note that boot emits an ApplicationEvent
of type JobExecutionEvent
with the JobExecution
as payload. So you can create a bean that implements ApplicationListener<JobExecutionEvent>
and gracefully shutdown the application context if the job fails.
Hope this helps.
Upvotes: 1