Feb 14th, 2013, 11:28 AM
OptimisticLockingFailureException when stop the job at its ending stage
I have a spring batch job running in asynchronous mode and issue the stop operation through JobOperator in a virgo OSGi container. OptimisticLockingFailureException can be thrown if the job is at the last moment to update the JobExecution status to COMPLETED because it detects the version conflicts.
I noticed two related Jira issues were opened.
The first issue had been resolved since 2.0.0.M4 but I am using 2.1.8.RELEASE.
The second issue reported similar problem when the job is at STARTING status. It is still open.
Is my problem a valid issue? Any solution already? Thanks.
Robert commented in BATCH-954 back in 2008
"JobOperator works with its own copy of JobExecution therefore the version mismatch between job's and jobOperators' version is inevitable. This issue fixed the obvious problem (when jobOperator updates the status, job's version becomes obsolete), but I think there can still be trouble with race conditions. I want to take a closer look at this in BATCH-961"
Is this really inevitable? Then what is the best practice to stop a job running asynchronous mode? Thanks again.