【发布时间】:2019-12-04 17:47:47
【问题描述】:
我有一个 Spring Batch 应用程序,它在 write 步骤期间循环遍历要插入 Postgres 数据库的记录。我们时不时地在循环中得到一个DuplicateKeyException,但不希望整个工作失败。我们记录该记录并希望继续插入以下记录。
但是一旦出现异常,事务就会变成“坏”并且 Postgres 将不再接受任何命令,如 in this excellent post 所述。所以我的问题是,重启交易的最佳方式是什么?同样,我不会重试失败的记录 - 我只想继续循环下一条记录。
这是我的工作配置 xml 的一部分:
<batch:job id="portHoldingsJob">
<batch:step id="holdingsStep">
<tasklet throttle-limit="10">
<chunk reader="PortHoldingsReader" processor="PortHoldingsProcessor" writer="PortHoldingsWriter" commit-interval="1" />
</tasklet>
</batch:step>
<batch:listeners>
<batch:listener ref="JobExecutionListener"/>
</batch:listeners>
</batch:job>
感谢您的任何意见!
【问题讨论】:
标签: spring-data-jpa spring-batch