Results 1 to 3 of 3

Thread: Which threadsafe JobRepository for multithreaded Step?

  1. #1
    Join Date
    Jan 2012
    Posts
    11

    Question 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. #2
    Join Date
    Sep 2008
    Location
    Chicagoland, IL
    Posts
    351

    Default

    Could you post your job configuration?
    Michael Minella
    Spring Batch Lead
    Author - Pro Spring Batch
    http://www.michaelminella.com
    Twitter: @MichaelMinella

  3. #3
    Join Date
    Jan 2012
    Posts
    11

    Default 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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •