Spring Batch JdbcBatchItemWriter

问题描述 投票:2回答:2

我正在与读者和作家一起使用。读者正在使用具有高页面大小5000的JdbcPagingItemReader。编写器在块步骤上使用JdbcBatchItemWriter,提交间隔为5000。

    <batch:step id="createRecords">
                    <tasklet  allow-start-if-complete="true" >
                        <chunk reader="readTable"  writer="createNewRecords" 
                               commit-interval="5000" skip-limit="100" >
                       <skippable-exception-classes>
                       <batch:include class="java.lang.Exception"/>
                       </skippable-exception-classes>
                        </chunk>
                    </tasklet>
</batch:step>

当我使用这个块步骤来加载记录时,一切都按照我的预期运行。它一次插入5000条记录(当没有错误时),性能如预期。一分钟内处理10000条记录等

但是,当我使用相同的块步骤(完全相同的读取器)并更改编写器使用的SQL来执行UPDATE语句时(如在基本SQL更新中与INSERT相反),应用程序最多需要30分钟才能完成更新50K记录,这是差的。 SQL中的单个更新语句(几乎相同)对于整个表在几秒钟内运行。如果可能的话,我想利用批处理。

     <bean id="createNewRecords" class="org.springframework.batch.item.database.JdbcBatchItemWriter">
    <property name="dataSource" ref="dataSource" />   
    <property name="sql">
        <value>
            <![CDATA[        
            UPDATE  TABLE SET TABLE_COLUM = :test
            ]]>
        </value>
    </property>
    <property name="itemSqlParameterSourceProvider">
        <bean class="org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider" />
    </property>        
</bean>

想知道这听起来像配置问题 - 或者春季批次JdbcBatchItemWriter对更新语句的处理方式不同?

java spring integration batch-processing enterprise
2个回答
0
投票

架构中是否有任何触发器?如果是,那么可能是问题所在。

无论如何,我也会尝试减少提交间隔。 5000在我看来相当大,因为你说单个更新执行速度很快,这可能会有所帮助。


0
投票

您的更新查询在每次调用时都会更新表中的每一行。它需要一个“where”子句,理想情况下基于唯一或主键索引。

© www.soinside.com 2019 - 2024. All rights reserved.