Spring Batch 中的作业级事务性 [英] Job level Transactionality in Spring Batch

查看:103
本文介绍了Spring Batch 中的作业级事务性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在知道 Spring-Batch 中没有步骤间事务性这样的东西.我正在开发一个复杂的批处理作业,其中有许多步骤在数据库中执行多个操作,并且每个步骤都与其他步骤相关,这样每个步骤都属于同一个事务.我理解 Spring-Batch 范式的方式我必须使用一步工作来实现事务性.是否有任何想法(或任何其他方式)在最近或未来的版本中具有某种工作级别的事务性?

I know right now there is no such thing as inter-step transactionality in Spring-Batch. I'm developing a complex batch job, with many steps performing several actions in database, and each one is related with the others, in such way that each one of them belongs to the same transaction. The way I understand the Spring-Batch paradigm I'm bound to use one-step job in order to have transactionality. Is there any thought (or any other way) to have some kind of job-level transactionality in lately or future versions?

Edit1:我在这个 link 中发现,点6.3.1,一种连接多个处理器的方法,但不能满足我当前的需求.

I have found in this link, point 6.3.1, a way to concatenate several processors, but that doesn't fulfill my current needs.

Edit2:另一个 link 建议我使用带有@Transactional"注释的信封类的可能性,该类将调用我的工作,因此应具有外部事务.

This other link suggests me the possibility of using an envelope class with "@Transactional" annotation that will invoke my job and, therefore, shall have an external transaction.

推荐答案

我终于找到了一种方法.如上一版所述,您必须从事务方法调用作业:

Finally I have found a way to do this. As said in the last edition you must invoke the job from a transactional method:

@Transactional(propagation=Propagation.REQUIRED)

@Transactional(propagation=Propagation.REQUIRED)

在此级别中将传播级别设置为所需非常重要.并将作业级别传播设置为强制",从而实现作业和步骤将其事务添加到当前事务.尽管如此,正如 Michael Lange 所写,重要的是要考虑您正在管理的潜在卷大小,以避免超出限制的提交或回滚.

It's important set the propagation level to required in this level. And set the job level propagation to "mandatory", achieving with this the job and steps add their transactions to the current one. Nevertheless, as Michael Lange wrote, it's important to consider the potential volume size you are managing, in order to avoid out-of-the-limit commits or rollbacks.

这篇关于Spring Batch 中的作业级事务性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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