繁体   English   中英

jdbcItemReader 支持分区吗?

[英]jdbcItemReader support for partitioning?

使用 https ://github.com/jberet/jberet-support中的 jdbcItemReader 并希望使用分区来加快处理速度。

分区数(此处为 16)对重复写入的数据有副作用。 每个分区对相同的数据执行相同的工作,而不是将输入数据集拆分为 n 个不同的分区。

已编辑:下面的代码显示了实现它的正确方法。 注意:您的 SQL 查询需要返回有序数据:N 个分区,这里是 16,表示 16 个读卡器将运行查询!

 <reader ref="jdbcItemReader">
                <properties>
                    <property name="beanType" value="java.util.Map"/>
                    <property name="sql" value="select ......"/>
                    <property name="url"
                              value="jdbc:oracle:thin:......"/>
                    <property name="user" value="......."/>
                    <property name="password" value="....."/>
                    <property name="columnMapping" value="xxxx, xxxx"/>
                    <property name="columnTypes" value="String,String"/>
                    <property name="start" value="#{partitionPlan['partition.start']}"/>
                    <property name="end" value="#{partitionPlan['partition.end']}"/>
                    <!--CONCUR_READ_ONLY: If you set this as a value of the concurrency while creating the ResultSet object you cannot update the contents of the ResultSet you can only read/retrieve them.-->
                    <!--CONCUR_UPDATABLE: If you set this as a value of the concurrency while creating the ResultSet object you can update the contents of the ResultSet.-->
                    <!--TYPE_SCROLL_SENSITIVE: ResultSet is sensitive to the changes that are made in the database i.e. the modifications done in the database are reflected in the ResultSet.-->
                    <property name="resultSetProperties"
                              value="fetchSize=5500, resultSetConcurrency=CONCUR_READ_ONLY,
                              fetchDirection=FETCH_REVERSE,
                              resultSetType=TYPE_SCROLL_SENSITIVE,
                              resultSetHoldability=HOLD_CURSORS_OVER_COMMIT"/>
                </properties>
            </reader>
            <processor ref="myProcessort"/>
            <writer ref="myWriter"/>
        </chunk>

<!-- run your sql with a count to define partitions evenly -->
        <partition>
            <plan partitions="16" threads="16">
                <properties partition="0">
                    <property name="partition.start" value="0"/>
                    <property name="partition.end" value="500"/>
                </properties>
                <properties partition="1">
                    <property name="partition.start" value="500"/>
                    <property name="partition.end" value="1000"/>
                </properties>
       <!-- ... -->
                <properties partition="15">
                    <property name="partition.start" value="5000"/>
                    <property name="partition.end" value="5500"/>
                </properties>

您需要像在第二个 XML 代码段中那样定义步骤分区。 然后在jdbcItemReader中定义startend属性,这两个属性分别引用分区属性partition.startpartition.end

这 2 个分区属性可以命名不同,只要它们在partitionitem-reader元素中是一致的。

例如,

<reader ref="jdbcItemReader">
  <properties>
    <property name="start" value="#{partitionPlan['partition.start']}"/>
    <property name="end" value="#{partitionPlan['partition.end']}"/>
</properties>
</reader>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM