Due to limitations of integrating with existing application we need to use a separate database connection per chunk and manage the commit boundary one commit at the end of chunk. We designed to use remote partitioning and process multiple partitions at workers. partition step expected to execute chunks sequentially.
We tried an approach of combining Chink Listener and processor, connection obtained at before chunk listener method as instance variable and using it while processing,
but this connection being replaced right after the first item processed by beforeChunk method. Used Resource less Transaction manager in this case. How ever this transaction manager is not recommended to use for production. We are expected to process chunks in parallel and not expected this. We have also observed that when we hold the connection at writer by beforeChunk method is getting closed when write method called.
Second approach by using DataSourceTransactionManager , but not sure how to get the connection from transaction used at chunk level.
Step Configuration as follows:-
<step id="senExtractGeneratePrintRequestWorkerStep" xmlns=http://www.springframework.org/schema/batch>
<tasklet>
<chunk reader="senExtractGeneratePrintRequestWorkerItemReader"
processor="senExtractGeneratePrintRequestWorkerItemProcessor"
writer="senExtractGeneratePrintRequestWorkerMultiItemWriter"
commit-interval="${senExtractGeneratePrintRequestWorkerStep.commit-interval}"
skip-limit="${senExtractGeneratePrintRequestWorkerStep.skip-limit}">
<skippable-exception-classes>
<batch:include class="java.lang.Exception" />
</skippable-exception-classes>
</chunk>
<listeners>
<listener ref="senExtractGeneratePrintRequestWorkerItemProcessor" />
</listeners>
</tasklet>
</step>
<bean id="senExtractGeneratePrintRequestWorkerItemProcessor"
scope="step"
class="com.abc.batch.senextract.worker.SENExtractGeneratePrintRequestItemProcessor"/>
Connection is closed by datasource before write is called. Screen shots of call hierarchy as below. enter image description here