在Spring批处理中,您可以像这样设置事务isolation
和propagation
:
<job id="someJob" xmlns="http://www.springframework.org/schema/batch">
<step id="readWriteDate">
<tasklet transaction-manager="transactionManager">
<transaction-attributes isolation="DEFAULT" propagation="REQUIRED" timeout="30"/>
<chunk reader="dbItemReader" processor="dbItemProcessor" writer="dbItemWriter"
commit-interval="2" />
</tasklet>
</step>
</job>
我找不到java配置等效。
答案 0 :(得分:2)
@Configuration
public class StepWithTx {
@Autowired
private StepBuilderFactory steps;
@Bean
public Step step() throws Exception {
return steps
.get("CustomTxStep")
.<String, String>chunk(10)
.transactionAttribute(transactionAttribute...)
.reader(reader...)
.processor(processor...)
.writer(writer...)
.build();
}
}
答案 1 :(得分:1)
就像迈克尔·普拉洛(Michael Pralow)所说的那样。仅添加一个具体示例,您可以通过实例化默认事务属性来设置隔离级别:
DefaultTransactionAttribute transactionWithIsolationReadCommited = new DefaultTransactionAttribute(); transactionWithIsolationReadCommited.setIsolationLevel(TransactionAttribute.ISOLATION_READ_COMMITTED);
然后在步骤构建器中使用它。希望对您有帮助!