When Spring Batch is executed continuously in Oracle, ORA-08177

phenomenon

Launch the job almost immediately, as in the code below.

ExecutorService s = Executors.newFixedThreadPool(2);

long time1 = new Date().getTime();
long time2 = time1 + 111111000;
s.execute(() -> doBatch(time1));
s.execute(() -> doBatch(time2));

void doBatch(long t) {
    Map<String, JobParameter> p = new HashMap<String, JobParameter>();
    p.put("a", new JobParameter(new Date(t)));
    JobParameters jobParameters = new JobParameters(p);
    l.run(job, jobParameters)

When I do this, I get the following error:

Exception in thread "pool-1-thread-1" org.springframework.dao.CannotSerializeTransactionException: PreparedStatementCallback; SQL [INSERT into BATCH_JOB_INSTANCE(JOB_INSTANCE_ID, JOB_NAME, JOB_KEY, VERSION) values (?, ?, ?, ?)]; ORA-08177:Unable to serialize access for this transaction
; nested exception is java.sql.SQLException: ORA-08177:Unable to serialize access for this transaction

	at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:270)
	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
	at org.springframework.jdbc.core.JdbcTemplate.translateException(JdbcTemplate.java:1444)
	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:632)

The cause of this is [Spring Batch ORA-08177: can't serialize access for this transaction when running single job, SERIALIZED isolation level](https://stackoverflow.com/questions/22364432/spring-batch-ora-08177-cant] -serialize-access-for-this-transaction-when-running) is written.

solution

So you can change IsolationLevel to READ_UNCOMMITTED </ code>.

@Configuration
@EnableBatchProcessing
public class BatchConfiguration1 extends DefaultBatchConfigurer {
    @Autowired
    DataSource configDataSource;

    @Autowired
    PlatformTransactionManager configTxManager;

    @Override
    protected JobRepository createJobRepository() throws Exception {
        JobRepositoryFactoryBean factoryBean = new JobRepositoryFactoryBean();
        factoryBean.setDataSource(configDataSource);
        factoryBean.setTransactionManager(configTxManager);
        factoryBean.setIsolationLevelForCreate("ISOLATION_READ_COMMITTED");
        factoryBean.setTablePrefix("BATCH_");
        try {
            factoryBean.afterPropertiesSet();
            return factoryBean.getObject();
        } catch (Exception e) {
            throw new BatchConfigurationException(e);
        }
    }

Recommended Posts

When Spring Batch is executed continuously in Oracle, ORA-08177
Loop step in Spring Batch
Behavior when each is executed in the reverse order Range
ProxyFactory is convenient when you want to test AOP in Spring!
What is @Autowired in Spring boot?
Event processing is performed in Spring.
How to solve the problem that it is not processed normally when nesting beans in Spring Batch
Initial value when there is no form object property in Spring request
Spring Autowired is written in the constructor
Command when dependency is broken in Ubuntu 20.04
Error in implementation when implementing Spring validation
Behavior when wild card (**) is specified in ruby
Spring MVC: What happens when `@ RequestParam` is omitted
@Import target is treated as @Configuration in spring
Summary of what I learned in Spring Batch
When the project is not displayed in eclipse
Ebean.update () is not executed in the inherited model.
When using Map for form in Spring, order is not guaranteed when submitting even LinkedHashMap