首页 文章

多线程作业中的Spring Batch Reader

提问于
浏览
6

当读者是 org.springframework.batch.item.database.JpaPagingItemReader 时,我正在使用Spring Batch来运行我的JOBS

我的JOB配置参数: throttle-limit="6"

从读卡器读取数据时是否存在线程数据冲突?

为什么我要恢复以下警告:

[org.springframework.batch.core.step.item.ChunkMonitor:109] - No ItemReader set (must be   concurrent step), so ignoring offset data.
[org.springframework.batch.core.step.item.ChunkMonitor:141] - ItemStream was opened in a different thread.  Restart data could be compromised.
[org.springframework.batch.core.step.item.ChunkMonitor:141] - ItemStream was opened in a different thread.  Restart data could be compromised.
[org.springframework.batch.core.step.item.ChunkMonitor:141] - ItemStream was opened in a different thread.  Restart data could be compromised.

1 回答

  • 5

    虽然 JpaPagingItemReader 是线程安全的,因为使用它从多个线程读取是可以的,当通过多个线程使用时,该读取器将不支持重启 . 警告实际上表示您需要将保存状态设置为false( JpaPaginingItemReader#setSaveState(boolean) ) . 此类的文档讨论了在此处将保存状态设置为false的必要性:http://docs.spring.io/spring-batch/trunk/apidocs/org/springframework/batch/item/database/JpaPagingItemReader.html

    这样做的原因是重启状态最终在所有线程之间共享,因此它们最终会相互踩踏 .

相关问题