We are facing the above issue when we try to run multiple job at the same time .
Below is the functionality of one of the tasklet in spring batch job.
Tasklet1 : generate message for external system A , persist the message id , send message to external system ,stop the spring batch job (I am stopping this job since I don't have any control over the external system ,I don't know when I will receive response from the system)
Below is the listener which is always running to listen to the external system 's response .
listener1 -listener to listen response from external system A ,the moment response is received , listener class restart the same job by getting job id persisted in the DB .
If i run one or two jobs , it gets completed without any issue , but if I try to run 20 jobs in parallel then at least 5 are getting failed with the above exception as mentioned in the title.
I am not sure what should i do here so that all jobs gets completed .
I have already change "isolation-level-for-create" to "READ_COMMITTED" , that did not help me .
Any help would be highly appreciated .
Thanks.
UPDATE: I have tried to create bean for job repository and use aop as shown below.
<aop:config>
<aop:pointcut id="allRepositoryMethods"
expression="execution(* org.springframework.batch.core..*Repository+.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="allRepositoryMethods" />
</aop:config>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="*" isolation="READ_COMMITTED" />
</tx:attributes>
</tx:advice>
But this is throwing the error
"IllegalStateException Existing transaction detected in JobRepository. Please fix this and try again (e.g. remove @Transactional annotations from client)"
I have made sure to remove @Transactional if any in all methods , but still i am getting the above error .
Any idea ?
.