简体   繁体   中英

Spring batch- parallel processing of two tasks but second task has dependency on first task

I am using spring batch for processing large data .

My problem is I have two different Tasklet that are executing one after another . I can not run it parallel as second tasklet has some dependency one first Tasklet . In order to save the time I would like to start next Tasklet immediately after the first few items has been processed by previous tasklet . As Spring Batch uses a Chunk Oriented processing style. Can ItemWriter of one Tasklet , pass chunk of already processed items to another Tasklet 's ItemReader or ItemProcessor or ItemWriter for next processing? But while the another tasklet is working on the chunk , previous tasklet should NOT wait and it should continue iteration over next chunk .

Based on your description and additional information above, I would simply leverage a CompositeItemWriter to accomplish this.

The list of items will first be written by WriterOne and then be passed to and written by WriterTwo.

<bean id="compositeWriter" 
        class="org.springframework.batch.item.support.CompositeItemWriter">
    <property name="delegates">
        <list>
            <ref bean="writerOne" />
            <ref bean="writerTwo" />
        </list>
    </property>
</bean>

<bean id="writerOne"  ...  />
<bean id="writerTwo"  ...  />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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