0
votes

I'm running a remote partitioned job and need to intercept a kill signal and stop the job gracefully in order to be able to resume on the next run. I’ve tried to do that using SimpleJobOperator by simply calling jobOperator.stop(jobExecudtionId) in a method annotated with @PreDestroy in the batch configuration. But this doesn’t seem to be thread-safe. The EntityManager is closed before all worker steps get the chance to rollback and I get a Failed to obtain JDBC Connection: Session/EntityManager is closed error in all the worker threads.

How can this be done in a thread-safe manner?