Spring batch ItemProcessor order of processing the items -


here spring configuration file.

<batch:job id="emptxnjob">     <batch:step id="stepone">         <batch:partition partitioner="partitioner" step="worker" handler="partitionhandler" />     </batch:step> </batch:job>  <bean id="asynctaskexecutor" class="org.springframework.core.task.simpleasynctaskexecutor" />  <bean id="partitionhandler" class="org.springframework.batch.core.partition.support.taskexecutorpartitionhandler" scope="step">     <property name="taskexecutor" ref="asynctaskexecutor" />     <property name="step" ref="worker" />     <property name="gridsize" value="${batch.gridsize}" /> </bean>  <bean id="partitioner" class="com.spring.mybatch.emptxnrangepartitioner">     <property name="emptxndao" ref="emptxndao" /> </bean>  <batch:step id="worker">     <batch:tasklet transaction-manager="transactionmanager">         <batch:chunk reader="databasereader" writer="databasewriter" commit-interval="25" processor="itemprocessor">         </batch:chunk>     </batch:tasklet> </batch:step>  <bean name="databasereader" class="org.springframework.batch.item.database.jdbccursoritemreader" scope="step">     <property name="datasource" ref="datasource" />     <property name="sql">         <value>             <![cdata[                     select *                                              emp_txn                                              emp_txn_id >= #{stepexecutioncontext['minvalue']}                      ,                          emp_txn_id <= #{stepexecutioncontext['maxvalue']}             ]]>         </value>     </property>     <property name="rowmapper">         <bean class="com.spring.mybatch.emptxnrowmapper" />     </property>     <property name="verifycursorposition" value="false" /> </bean>  <bean id="databasewriter" class="org.springframework.batch.item.database.jdbcbatchitemwriter">     <property name="datasource" ref="datasource" />     <property name="sql">         <value><![cdata[update emp_txn set txn_status=:txnstatus emp_txn_id=:emptxnid]]></value>     </property>     <property name="itemsqlparametersourceprovider">         <bean class="org.springframework.batch.item.database.beanpropertyitemsqlparametersourceprovider" />     </property> </bean>  <bean id="itemprocessor" class="org.springframework.batch.item.support.compositeitemprocessor" scope="step">     <property name="delegates">         <list>             <ref bean="processor1" />             <ref bean="processor2" />         </list>     </property> </bean> 

my custom range partitioner split based on primary key of emp_txn records.

assume emp(primary key - emp_id) can have multiple emp_txn(primary key - emp_txn_id) processed. current setup, possible in itemprocessor(either processor1 or processor 2) 2 threads can process emp_txn same employee(i.e., same emp_id).

unfortunately end logic process(in processor2) emp_txn not capable of handling transactions same emp in parallel. there way in spring batch control order of such processing?

with use case describing, think you're partitioning wrong thing. i'd partition emp instead of emp-txn. group emp-txns , order them there. prevent risk of emp-txns being processed out of order based on thread gets first.

to answer direct question, no. there no way order items going through processors in separate threads. once break step partitioning, each partition works independently.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -