Announcement Announcement Module
Collapse
No announcement yet.
Which threadsafe JobRepository for multithreaded Step? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Which threadsafe JobRepository for multithreaded Step?

    Hi,
    I am currently using spring batch admin module for my project. The default implementation uses JobRepositoryFactoryBean to produce SimpleJobRepository bean.
    When I execute a step multithreadedly with SimpleAsyncTaskExecutor, I get this error:
    Code:
    org.springframework.dao.OptimisticLockingFailureException: Attempt to update step execution id=2 with wr
    ong version (1), where current version is 2
            at org.springframework.batch.core.repository.dao.JdbcStepExecutionDao.updateStepExecution(JdbcSt
    epExecutionDao.java:185)
            at org.springframework.batch.core.repository.support.SimpleJobRepository.update(SimpleJobReposit
    ory.java:171)
    How can I make it threadsafe ?
    Thank you.
    K.

  • #2
    Could you post your job configuration?

    Comment


    • #3
      job configuration

      Hi Minella,
      Here is my configuration:

      Code:
      <bean id="taskExecutor" class="org.springframework.core.task.SimpleAsyncTaskExecutor"/>
      
      
      <bean id="articleReader" class="a.b.c.ThreadSafeHibernateCursorItemReader" scope="step">
      		<property name="sessionFactory" ref="sessionFactory" />
      		<property name="queryString" value="select o.id from Article o where o.status = 4" />
      		<property name="useStatelessSession" value="true" />
      		<property name="saveState" value="false" />
      </bean>
      	
      	<bean id="crawlingProcessor" class="a.b.c.CrawlingProcessor" scope="step" autowire="byType">
      		<property name="processingRuleParser">
      			<bean class="a.b.c.ProcessingRule">
                  	<property name="config" value="#{jobParameters['config.folder']}/processing.conf"/> 
      				<property name="resources" value="#{jobParameters['config.folder']}/*.xml"/> 
                  </bean>
      		</property>
      	</bean>
      
      <batch:job id="ArticlesJob">
      		<batch:step id="ArticlesStep1">
      			<batch:tasklet task-executor="taskExecutor" throttle-limit="5">
      				<batch:chunk commit-interval="5" reader="articleReader" processor="crawlingProcessor" writer="nullWriter" skip-limit="10">
      				<batch:skippable-exception-classes>
                  		<batch:include class="org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException"/>
                  		<batch:include class="org.springframework.dao.CannotAcquireLockException"/>
                  		<batch:include class="org.springframework.dao.OptimisticLockingFailureException"/>
                  		<batch:include class="org.hibernate.StaleObjectStateException"/>
               		</batch:skippable-exception-classes>
      				</batch:chunk>
      			</batch:tasklet>
      		</batch:step>
      </batch:job>
      Most of the spring batch admin context bean is used as default.

      The only thing is that I have a transaction manager defined in a applicationContext.xml of a common library:

      Code:
      <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
      		<property name="sessionFactory" ref="sessionFactory" />
      </bean>
      Thanks.

      Comment

      Working...
      X