There are a lot of examples which use FlatFileItemReader
along with TaskExecutor
. I provide samples below (both with XML and Java Config):
I have used it my self with XML configuration for large CSVs (GB size) writing to database with the out-of-the-box JpaItemWriter
. There seem to be no issues even without setting save-state = false or taking any kind of special handling.
Now, FlatFileItemReader
is documented as not thread-safe.
My guess was that JpaItemWriter
was "covering" the issue by persisting Sets i.e. collections with no duplicates if the hashCode()
and equals()
were covering the business key of the Entity. However, even this way it is not enough to prevent duplicates due to non-thread safe reading and processing.
Could you please clarify: is it proper/correct/safe to use the out-of-the-box FlatFileItemReader
within a Tasklet which has assigned a TaskExecutor? Regardless of the Writer. If not, how could we explain in theory the lack of errors when a JPAItemWriter
is used?
P.S: The example links that I give above, use FlatFileItemReader
with TaskExecutor without mentioning at all possible thread-safety issues...
JpaItemWriter
is thread-safe whenFlatFileItemReader
is not? – RobynJpaItemReader
orJpaItemWriter
? – Amir