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.

OptimisticLockingFailureException

Oct 19th, 2010, 09:48 AM

Hi,

I am getting below exception when I ran same job with different job parameters through multiple threads.

I have a job which will be executed to process a file.
To process multiple files, I have used threads to execute each File in different thread. where each thread processes a Same job with different job parameters.

Can someone tell me if I need to do any changes to overcome this exception.
Or If there is a best approach to handle my scenario.

Thanks in advance for the response.

Code:

org.springframework.dao.OptimisticLockingFailureException: Attempt to update step execution id=0 with wrong version (1), where current version is 2
at org.springframework.batch.core.repository.dao.MapJobExecutionDao.updateJobExecution(MapJobExecutionDao.java:93)
at org.springframework.batch.core.repository.support.SimpleJobRepository.update(SimpleJobRepository.java:155)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy8.update(Unknown Source)
at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:329)
at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:120)
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:49)
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:114)
at com.cme.marketdata.fix2rlc.service.JobExecutorTask.execute(JobExecutorTask.java:63)

The best thing you can do is not use the Map JobRepository. Upgrading to the latest Spring Batch release might also help - there is some measure of thread safety in later version of the map repository, but it still isn't a perfect replacement for the RDBMS.