【问题标题】:Spring Batch JdbcBatchItemWriterSpring Batch JdbcBatchItemWriter
【发布时间】:2013-04-03 17:55:05
【问题描述】:

我正在对读取器和写入器使用块步骤。读取器使用 JdbcPagingItemReader,页面大小为 5000。写入器在块步骤上使用 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 条记录等。

但是,当我使用相同的块步骤(完全相同的读取器)并更改编写器用于执行 UPDATE 语句的 SQL(如在基本 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


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-11-28
        • 1970-01-01
        • 2019-06-09
        • 2018-10-26
        • 1970-01-01
        • 2018-07-10
        相关资源
        最近更新 更多