Spring批处理中的提交间隔和处理回滚 [英] commit-interval in Spring batch and dealing with rollbacks

查看:31
本文介绍了Spring批处理中的提交间隔和处理回滚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题与 Spring 批处理和事务有关.

My question relates to Spring batch and transactions.

假设我为我的步骤之一选择了 提交间隔 50.

Say I've chosen a commit-interval of 50 for one of my steps.

另外假设我总共有 1000 条记录,其中一条会导致 itemWriter 失败,从而导致整个块的回滚(在我的示例中为 50 条记录).

Also suppose I have 1000 records in all and amongst those records one will cause the itemWriter to fail thereby causing a rollback of the entire chunk (50 records in my example).

确保在作业完成(并忽略有问题的块)后将 49 条有效记录写入数据库的状态是什么?

What are the stategies to make sure that the 49 valid records are written to database after the job has completed (and ignored the problematic chunk)?

推荐答案

经过一番研究,我想出了以下几点:

After some researching, I came up with the following:

如果一个项目编写者未能提交一个块(这里是 50 个项目)从而导致回滚,Spring Batch 将单独重新运行有问题的块的每个项目,每个项目都有一个提交/事务.

If an item writer fails to commit a chunk (here 50 items) thereby causing a rollback, Spring Batch will rerun each item of the problematic chunk individually with one commit/transaction for each item.

因此,除了导致 Spring Batch 回滚块的一项之外,所有 49 项都将出现在数据库中.

Therefore, all 49 items will be present in database except the one item that caused Spring Batch to roll back the chunk.

这篇关于Spring批处理中的提交间隔和处理回滚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆