我在使Task Executor和块大小一致时遇到问题。下面是我的代码片段,我希望一个线程读取4000条记录,然后发送到ItemWriter,但是当我调试put日志时,显示每个线程具有不同的块大小,这是不一致的。如果我的块大小是4000,一个线程处理4000,其他可能是900,其他可能是3000.我使用ThreadPoolExecutor作为Task Executor。
My requirement is to process each chunk in parallel ..
<batch:step id="loadPayments" next="archiveFileStep">
<batch:tasklet task-executor="taskLetExecutor">
<batch:chunk reader="itemReader" writer="itemWriter" commit-interval="4000">
<batch:listeners>
<batch:listener>
<bean class="com.jpmc.cib.p3.batch.integration.samples.payments.PaymentChunkListener"/>
</batch:listener>
</batch:listeners>
</batch:chunk>
</batch:tasklet>
</batch:step>
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(20);
taskExecutor.setMaxPoolSize(100);
taskExecutor.setQueueCapacity(1000);
另外,我将ItemReader设为同步...
@Override
protected synchronized T doRead() throws Exception {
return super.doRead();
}