Multithreaded job hangs on @Transactional methods
I have a simple spring batch job with one step.
- reads records from a database
- updates the records with an "in process" flag
- does some work
- updates the database
All the data access is via JPA.
This job works fine as a single-threaded job, but when I try to run multiple threads (by adding a SimpleAsyncTaskExecutor with throttle-limit > 1), the job hangs as soon as it encounters:
a) a method with a @Transactional annotation, or
b) an entityManager query in non-@Transactional methods.
It seems like spring is deadlocking while trying to bind the entityManager to a thread. We are using the same transactionManager and dataSource for the jobRepository and our business tables, which might be part of the problem.
Does anyone know what we are doing wrong?