Framework/Batch

Spring Batch 실행시 ORA-08177: can't serialize access for this transaction 오류 조치

호형 2021. 9. 10. 11:38

Spring Batch를 실행할 때 ORA-08177: can't serialize access for this transaction (이 트랜잭션에 대한 직렬화 액세스를 할 수 없습니다) 오류가 발생하였다. 여러개의 Spring Batch Job이 하나의 JobRepository를 가지고 동시에 실행이 될 때 발생할 수 있는 문제이다. 이는 JobRepository 설정 중 transactionManager의 IsolationLevelForCreate 속성은 따로 지정하지 않을 경우 디폴트 값인 ISOLATION_SERIALIZABLE으로 설정되기 때문이다. 이를 ISOLATION_DEFAULT으로 변경하면 문제는 해결된다. 

 

변경을 하는 방법은 다음과 같다. 

Java Config

@Bean
public JobRepository jobRepository() throws Exception {
    JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
    factory.setDataSource(dataSource);
    factory.setTransactionManager(transactionManager());
    factory.setIsolationLevelForCreate("ISOLATION_DEFAULT");
    return factory.getObject();
}

 

Xml Config

<bean id="jobRepository" class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean"   
    p:dataSource-ref="batch.dataSource" 
    p:transactionManager-ref="transactionManager"   
    p:isolationLevelForCreate="ISOLATION_DEFAULT" />

 

끝!