Multiple Spring Batch jobs executing concurrently causing deadlocks in the Spring Batch metadata tables

China☆狼群 提交于 2019-11-30 19:48:12

After researching this further, and partially heading down the path of working on versions of the DAOs that back the JobRepository and work with SQL Server IDENTITY instead of sequences, I stumbled upon the way to address this without much more than a bit of configuration.

The simple way to address this is to configure the databaseType and isolationLevelForCreate properties of the JobRepository. Here are the settings I am using with SQL Server 2008:

<bean id="jobRepository"
    class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="transactionManager" ref="transactionManager" />
    <property name="databaseType" value="SQLSERVER" />
    <property name="isolationLevelForCreate" value="ISOLATION_REPEATABLE_READ" />
</bean>

I've tested this with 30 jobs (same job with different parameters) being launched by a group of Quartz jobs and thus far I haven't seen any issues.

I've also kept retry code (see comment on question) in place when launching the jobs just to catch any possible deadlocks and allow it to retry. It may be a moot point but I can't risk having jobs fail to launch.

I think that mentioning these settings in the Spring Batch documentation regarding launching multiple jobs at a given time when using SQL Server as your dataSource would be quite helpful to others. Then again, I guess not many people are stuck with SQL Server.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!