Announcement Announcement Module
Collapse
No announcement yet.
Batch OptimisticLockingFailureException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Batch OptimisticLockingFailureException

    Hi,

    I am using quartz to trigger my spring batch job.I have scenario where my quartz scheduler will automatically standby mode, then while resuming its firing my spring batch job but this throwing following exception.please if any one knows about this issue keep posted here.

    "org.springframework.batch.core.JobExecutionExcept ion: Flow execution ended unexpectedly
    at org.springframework.batch.core.job.flow.FlowJob.do Execute(FlowJob.java:105)
    at org.springframework.batch.core.job.AbstractJob.exe cute(AbstractJob.java:281)
    at org.springframework.batch.core.launch.support.Simp leJobLauncher$1.run(SimpleJobLauncher.java:120)
    at java.lang.Thread.run(Thread.java:619)
    Caused by: org.springframework.batch.core.job.flow.FlowExecut ionException: Ended flow=MappingJob at state=MappingJob.RuleSetValidation with exception
    at org.springframework.batch.core.job.flow.support.Si mpleFlow.resume(SimpleFlow.java:152)
    at org.springframework.batch.core.job.flow.support.Si mpleFlow.start(SimpleFlow.java:124)
    at org.springframework.batch.core.job.flow.FlowJob.do Execute(FlowJob.java:99)
    ... 3 more
    Caused by: org.springframework.dao.OptimisticLockingFailureEx ception: Attempt to update step execution id=2921 with wrong version (0), where current version is 0
    at org.springframework.batch.core.repository.dao.Jdbc StepExecutionDao.updateStepExecution(JdbcStepExecu tionDao.java:185)
    at org.springframework.batch.core.repository.support. SimpleJobRepository.update(SimpleJobRepository.jav a:167)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.aop.support.AopUtils.invokeJoi npointUsingReflection(AopUtils.java:307)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.invokeJoinpoint(ReflectiveMethodInvocat ion.java:183)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :150)
    at org.springframework.transaction.interceptor.Transa ctionInterceptor.invoke(TransactionInterceptor.jav a:107)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :172)
    at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:202)
    at $Proxy143.update(Unknown Source)
    at org.springframework.batch.core.step.AbstractStep.e xecute(AbstractStep.java:183)
    at org.springframework.batch.core.job.SimpleStepHandl er.handleStep(SimpleStepHandler.java:115)
    at org.springframework.batch.core.job.flow.JobFlowExe cutor.executeStep(JobFlowExecutor.java:61)
    at org.springframework.batch.core.job.flow.suppor"

  • #2
    Hard to say without more detail of the setup. It smells a bit like a Step being run in an enclosing transaction. What container are you running in?

    Please use [code][/code] tags for code and stack traces.

    Comment


    • #3
      I am using oracle weblogic server 10.3

      my job-launcher-context.xml looks like

      Code:
      <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://www.springframework.org/schema/beans"
      	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
      	xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      	xmlns:jee="http://www.springframework.org/schema/jee"
      	xmlns:batch="http://www.springframework.org/schema/batch" 
      	xsi:schemaLocation="
      		http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-2.5.xsd
      		http://www.springframework.org/schema/aop http://www.springframework.org/schem...ng-aop-2.5.xsd
      		http://www.springframework.org/schema/tx http://www.springframework.org/schem...ing-tx-2.5.xsd
      		http://www.springframework.org/schema/jee http://www.springframework.org/schem...ng-jee-2.0.xsd
      		http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd" >
      		
      
      	<jee:jndi-lookup id="dataSource" jndi-name="jdbc/oracledb" /> 
      
      	<bean id="transactionManager"
      		class="org.springframework.transaction.jta.WebLogicJtaTransactionManager">
      		<property name="allowCustomIsolationLevels" value="true" />
      		<property name="defaultTimeout" value="12000" />
      	</bean>
      	
      	<bean id="jobLauncher"
      		class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
      		<property name="jobRepository" ref="jobRepository" />
      		<property name="taskExecutor" ref="taskExecutor" />
      	</bean>
      	
      	<bean id="taskExecutor" class="org.springframework.core.task.SimpleAsyncTaskExecutor" />	 
      	
      	<bean
      		class="org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor">
      		<property name="jobRegistry" ref="jobRegistry" />
      	</bean>
      	
      	<bean id="jobRepository"
      		class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean"		
      		p:dataSource-ref="dataSource" p:transactionManager-ref="transactionManager" >	
      	</bean>
      	
      	<bean id="jobRegistry"
      		class="org.springframework.batch.core.configuration.support.MapJobRegistry" />
      
      	<bean id="jobOperator"
      		class="org.springframework.batch.core.launch.support.SimpleJobOperator"
      		p:jobLauncher-ref="jobLauncher" p:jobExplorer-ref="jobExplorer"
      		p:jobRepository-ref="jobRepository" p:jobRegistry-ref="jobRegistry" />
      
      	<bean id="jobExplorer"
      		class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean"
      		p:dataSource-ref="dataSource" />
      	
      	<batch:job id="globalParentleJob" abstract="true">
      		<batch:listeners>
      			<batch:listener ref="listener"/>
      		</batch:listeners>
      	</batch:job>
      	
      </beans>
      All my jobs are child jobs of this global parent job.
      Global parent job has only job level listener which updates my intermediate tables using iBatis SQL. iBatis using different data source.

      My Job file looks like

      Code:
      <?xml version="1.0" encoding="UTF-8"?>
      
      <beans:beans xmlns="http://www.springframework.org/schema/batch"
      	xmlns:beans="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop"
      	xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"
      	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
      	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
      http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd  http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
      http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">
      
      
      	<job id="MyJob" restartable="true" parent="globalParentleJob">
      		
      		<step id="RuleValidation">
      			<tasklet ref="ruleTasklet">
      				<listeners>
      					<listener ref="promotionListener" />
      				</listeners>
      			</tasklet>
      			<next on="INC" to="Inc" />
      			<next on="ITEMIDENTIFICATION" to="ItemIdentification" />
      			<end on="COMPLETED" />
      		</step>
      
      		<step id="Inc">
      			<tasklet ref="incTasklet">
      				<listeners>
      					<listener ref="promotionListener" />
      				</listeners>
      			</tasklet>
      			<next on="CONTINUEIDE" to="ItemIdentification" />
      			<end on="COMPLETED" />
      		</step>
      
      		<step id="ItemIdentification" next="limitDecider">
      			<tasklet ref="itemIdentificationTasklet">
      				<listeners>
      					<listener ref="promotionListener" />
      				</listeners>
      			</tasklet>
      		</step>
      
      		<decision decider="limitDecision" id="limitDecider">
      			<next on="CONTINUE" to="ItemIdentification" />
      			<next on="CONTINUEINC" to="Incremental" />
      			<next on="COMPLETED" to="SaveItemPartition" />
      		</decision>
      
      		<step id="stemPartition" parent="master">
      			<next on="TEST" to="MoveItemRecord" />
      			<next on="COMMITORINCREMENTAL" to="InspectTargetCharVal" />
      		</step>
      
      		<step id="InspectTargetCharVal" next="MoveItemRecord">
      			<tasklet ref="targetCharValTasklet" />
      		</step>
      
      		<step id="MoveItemRecord">
      			<tasklet ref="moveItemTasklet"></tasklet>
      			<next on="STAT-CONTINUE" to="StatisticsProcess" />
      			<end on="COMPLETED" />
      		</step>
      
      		<step id="StatisticsProcess" next="WkspcDelProcess">
      			<tasklet ref="ruleStatsTasklet"></tasklet>
      		</step>
      
      		<!-- Deleting from wkspc table -->
      		<step id="WkspcDelProcess">
      			<tasklet ref="wkspcDelTasklet" />
      			<next on="INCREMENTAL" to="ExecuteReports" />
      			<end on="COMPLETED" />
      		</step>
      
      		<step id="ExecuteReports">
      			<tasklet ref="executeCognosReport"></tasklet>
      		</step>
      	</job>
      
      	<step id="SaveItem">
      		<tasklet>
      			<chunk reader="itemAssignmentReader" writer="itemAssignmentWriter"
      				commit-interval="50"></chunk>
      		</tasklet>
      	</step>
      
      	<beans:bean id="ruleSetTasklet" scope="step"
      		class="com.service.batch.itemassignment.AssignmentRequestValidatorTasklet">
      	</beans:bean>
      
      	<beans:bean id="itemIdentificationTasklet"
      		class="com.service.batch.itemassignment.AssignmentProcTasklet"
      		scope="step">
      		<beans:property name="dataSource" ref="dataSource" />
      	</beans:bean>
      
      	<beans:bean id="incrementalTasklet"
      		class="com.service.batch.itemassignment.IncrementalTasklet"
      		scope="step">
      	</beans:bean>
      
      	<beans:bean id="promotionListener"
      		class="org.springframework.batch.core.listener.ExecutionContextPromotionListener"
      		scope="step">
      		<beans:property name="keys"
      			value="minValue,maxValue,factor,totalCnt,iterateValue,loopValue,rulesetIdList,ruleSetiterateValue,ruleSetloopValue,increRuleset,sourceSystemId" />
      	</beans:bean>
      
      	<beans:bean id="itemAssignmentReader"
      		class="com.service.batch.itemassignment.AssignmentJdbcItemReader"
      		scope="step">
      		<beans:property name="dataSource" ref="dataSource" />
      		<beans:property name="sql">
      			<beans:value>
      				<![CDATA[
      					SELECT colum
      					FROM table
      					filter 
      				 ]]>
      			</beans:value>
      		</beans:property>
      		<beans:property name="rowMapper">
      			<beans:bean
      				class="com.service.batch.itemassignment.AssignmentRowMapper" />
      		</beans:property>
      	</beans:bean>
      
      	<beans:bean id="itemAssignmentWriter"
      		class="com.service.batch.itemassignment.AssignmentWriter"
      		scope="step">
      		<beans:property name="appService" ref="itemAssignmentAppService" />
      	</beans:bean>
      	<beans:bean id="ruleStatsTasklet"
      		class="com.service.batch.itemassignment.RuleStatsTasklet"
      		scope="step">
      	</beans:bean>
      
      	<beans:bean id="targetCharValTasklet"
      		class="com.service.batch.itemassignment.TargetCharValTasklet"
      		scope="step">
      	</beans:bean>
      
      	<beans:bean id="wkspcDelTasklet"
      		class="com.service.batch.itemassignment.WkspcDelTasklet"
      		scope="step">
      	</beans:bean>
      
      	<beans:bean id="executeCognosReport" scope="step"
      		class="com.service.batch.itemassignment.ExecuteCognosReport">
      	</beans:bean>
      
      	<beans:bean id="limitDecision"
      		class="com.service.batch.itemassignment.LimitDecider">
      	</beans:bean>
      
      	<beans:bean id="itemAssignmentAppService"
      		class="com.service.itemassignment.ItemAssignmentAppService" />
      
      	<beans:bean id="moveItemTasklet"
      		class="com.service.batch.itemassignment.MoveProcTasklet"
      		scope="step">
      		<beans:property name="dataSource" ref="dataSource" />
      	</beans:bean>
      
      	<beans:bean id="master"
      		class="com.service.batch.itemassignment.ItemAssignmentPartitionStep">
      		<beans:property name="jobRepository" ref="jobRepository" />
      		<beans:property name="dataSource" ref="dataSource" />
      		<beans:property name="step" ref="SaveItem" />
      		<beans:property name="stepExecutionSplitter">
      			<beans:bean
      				class="org.springframework.batch.core.partition.support.SimpleStepExecutionSplitter">
      				<beans:constructor-arg ref="jobRepository" />
      				<beans:constructor-arg ref="SaveItem" />
      				<beans:constructor-arg>
      					<beans:bean
      						class="com.service.batch.itemassignment.ItemAssignmentRangePartitioner"
      						scope="step">
      						<beans:property name="dataSource" ref="dataSource" />
      					</beans:bean>
      				</beans:constructor-arg>
      			</beans:bean>
      
      		</beans:property>
      		<beans:property name="partitionHandler">
      			<beans:bean
      				class="org.springframework.batch.core.partition.support.TaskExecutorPartitionHandler">
      				<beans:property name="taskExecutor" ref="taskExecutor" />
      				<beans:property name="step" ref="SaveItem" />
      				<beans:property name="gridSize" value="3" />
      			</beans:bean>
      		</beans:property>
      	</beans:bean>
      
      </beans:beans>
      Last edited by mailtonbalaji; Mar 6th, 2011, 11:14 PM.

      Comment


      • #4
        Excellent, that's all very clear. What is missing is the detail of how the JobLauncher is called. Since you are in WLS there remains a suspicion that somehow the container is trying to control the transactions.

        Comment


        • #5
          From my quartz Job its using the below code to launch spring batch job.I was unable to interpret your last post could you please explain how the container can have an effect?

          Code:
          JobLauncher jobLauncher = (JobLauncher) factory.getBean("jobLauncher", SimpleJobLauncher.class);
          Job job = (Job) factory.getBean(jobName, Job.class);
          JobExecution execution = jobLauncher.run(job, jobParameters);

          Comment


          • #6
            There is still something missing. Is the JobLauncher being used inside an EJB or other JEE component? If so the container might be trying to start a transaction for it (which would be an error). As far as I know Quartz doesn't do this itself, but I don't know how it is set up in your environment, or what features are available there in WLS. (You could just use Spring 3.0 native scheduling features, and it would certainly be easier to reason about.)

            Comment


            • #7
              This is the target Job class of my quartz which launches my spring batch job from here.It not using EJB Component It uses the J2EE Component.Please give me some sample Job for Spring3.0 native scheduling.


              Code:
              package org.abc;
              import org.quartz.Job;
              
              public class SpringJob implements Job
              {
              
              public void execute(JobExecutionContext context) throws JobExecutionException {
              	JobLauncher jobLauncher = (JobLauncher) factory.getBean("jobLauncher", SimpleJobLauncher.class);
              	Job job = (Job) factory.getBean(jobName, Job.class);
              	JobExecution execution = jobLauncher.run(job, jobParameters);
              	
              	
              	}
              
              }

              Comment


              • #8
                I don't see anything wrong yet, and I'm not sure it's going to help, but at least we can take one thing out of the mix. You can find out more about Spring scheduling here: http://blog.springsource.com/2010/01...in-spring-3-0/ (and in the user guide).

                Comment

                Working...
                X