簡體   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