11

I'm Using Spring Batch to run my JOBS when the reader is org.springframework.batch.item.database.JpaPagingItemReader

And my JOB configured with the parameter: throttle-limit="6"

Is there any threads data conflict when reading data from the reader?

why i'm reviving the following warning:

[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.
Yosefarr
  • 709
  • 5
  • 12
  • 26

1 Answers1

8

While the JpaPagingItemReader is thread safe in that using it to read from multiple threads is ok, that reader will not support restart when used via multiple threads. The warnings are really there to indicate that you need to set the save state to false (JpaPaginingItemReader#setSaveState(boolean)). The documentation for this class discusses the need to set save state to false here: http://docs.spring.io/spring-batch/trunk/apidocs/org/springframework/batch/item/database/JpaPagingItemReader.html

The reason for this is that the restart state ends up being shared across all threads so they end up stepping on each other.

Michael Minella
  • 20,843
  • 4
  • 55
  • 67
  • Setting saveState as false doesn't really help :( – Selim Ok Nov 28 '14 at 13:28
  • We are using MongoItemWriter and according to doc it is also thread safe. But setting saveState=false didn't avoid the warning logs which are listed in original question. – Selim Ok Nov 28 '14 at 23:53
  • 7
    `saveState=false` won't get rid of the warnings...but it makes sure that you get the expected behaviors. – Michael Minella Nov 29 '14 at 00:00
  • Then it's OK :) (Note: While I wrote that comment we have had another consistency problem, that has another reason later we found. [The mongo pager doesn't work properly if we start multi threaded processor.] ) – Selim Ok Nov 29 '14 at 00:16