【问题标题】:Tasklet transaction-manager and chunk transactionTasklet 事务管理器和块事务
【发布时间】:2022-08-02 17:26:21
【问题描述】:

我指定了一个面向块的处理的小任务。

          <batch:step id=\"midxStep\" parent=\"stepParent\">
             <batch:tasklet transaction-manager=\"transactionManager\">
                    <batch:chunk
                           reader=\"processDbItemReaderJdbc\"
                           processor=\"midxItemProcessor\"
                           writer=\"midxCompositeItemWriter\"
                           processor-transactional=\"false\"
                           reader-transactional-queue=\"false\"
                           skip-limit=\"${cmab.batch.skip.limit}\"
                           commit-interval=\"#{jobParameters[\'toProcess\']==T(de.axa.batch.ecmcm.cmab.util.CmabConstants).TYPE_POSTAUSGANG ? \'${consumer.global.pa.midx.commitSize}\' : \'${consumer.global.pe.midx.commitSize}\' }\"
                           cache-capacity=\"20\">
                        <batch:skippable-exception-classes>
                            <batch:include class=\"de.axa.batch.ecmcm.cmab.util.CmabProcessMidxException\" />
                            <batch:exclude class=\"java.lang.IllegalArgumentException\" />
                        </batch:skippable-exception-classes>
                        <batch:retryable-exception-classes>
                            <batch:include class=\"de.axa.batch.ecmcm.cmab.util.CmabTechnicalMidxException\" />
                            <batch:include class=\"de.axa.batch.ecmcm.cmab.util.CmabTechnicalException\" />
                        </batch:retryable-exception-classes>
                        <batch:retry-listeners>
                            <batch:listener ref=\"logRetryListener\"/>
                        </batch:retry-listeners>
                        <batch:listeners>
                            <batch:listener>
                                <bean id=\"midxProcessSkipListener\" class=\"de.axa.batch.ecmcm.cmab.core.batch.listener.CmabDbSkipListener\" scope=\"step\">
                                    <constructor-arg index=\"0\" value=\"#{jobParameters[\'errorStatus\']}\" type=\"java.lang.String\"/>
                                </bean>
                            </batch:listener>
                        </batch:listeners>
                    </batch:chunk>
                    <batch:transaction-attributes isolation=\"SERIALIZABLE\" propagation=\"MANDATORY\" timeout=\"${cmab.jta.usertransaction.timeout}\"/>
                    <batch:listeners>
                        <batch:listener ref=\"midxStepListener\"/>
                        <batch:listener>
                            <bean id=\"cmabChunkListener\" class=\"de.axa.batch.ecmcm.cmab.core.batch.listener.CmabChunkListener\" scope=\"step\"/>
                        </batch:listener>
                    </batch:listeners>
             </batch:tasklet>
      </batch:step>

tasklet 使用 JtaTransaction 管理器(Atomikos,name=\"transactionManager\")运行。
现在我的问题:
这个事务管理器“委托”到块进程吗?
为什么我要问这个?如果我将事务属性(参见块)设置为传播级别“MANDATORY”,则块进程因没有可用事务的错误而中止。 因此它让我感到困惑,因为我认为 tasklet 事务规范意味着在这个 tasklet 事务中运行的块也是。

此外,我打算在具有多个 pod 的云系统中运行该应用程序。
进程 DbIemReaderJdbs 通过存储过程 ItemReader 从 PostgresDB 获取带有“FOR UPDATE SKIP LOCKED”的项目。
所以我的意图是运行块,也意味着读者,在事务以阻止读取器结果集到其他 POD 进程。

    标签: spring-batch


    【解决方案1】:

    事务属性用于 Spring Batch 将创建的事务,以使用您在步骤上设置的事务管理器运行您的步骤。这些是事务本身的属性,而不是事务管理器(这没有意义)。

    所有批处理工件都在同一事务的范围内执行,包括读取器和写入器。唯一的例外是JdbcCursorItemReader,默认情况下does not participate in the transaction,除非设置了useSharedExtendedConnection

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-02
      • 2017-06-23
      • 1970-01-01
      • 1970-01-01
      • 2016-05-17
      • 1970-01-01
      相关资源
      最近更新 更多