多线程作业中的Spring Batch Reader

时间:2014-05-21 10:30:16

标签: spring-batch

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

我的JOB配置参数: 的油门限值=" 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 个答案:

答案 0 :(得分:5)

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

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

相关问题