0

I am new to Spring Batch and tried using Spring Data Jpa. Seems that persisting the object using the CrudReposity opens the Db Connection for every record hurting the performance of the project.

Planning to move to spring jdbc with native query to improve the performance.Any suggestions?

Magg
  • 61
  • 1
  • 4
  • You should setup a connection pool, such as C3P0. https://stackoverflow.com/questions/23554873/configuring-c3p0-in-persistence-xml-with-jpa-and-hibernate – Fabio Manzano Aug 29 '18 at 18:00
  • Hi Fabio, i have setup the connection pool but the pool gets exhausted after running for 30 mins. Seems that connections not returned back to the pool. i am planning to open single connection (Long session) and do the commits in batch and close the connection. – Magg Aug 29 '18 at 18:05
  • Planning to open single connection (Long session) and do the commits in batch and close the connection. Cons: Have to reprocess again in case of connectivity loss – Magg Aug 29 '18 at 18:14
  • Are you closing your connections at all? Usually in the finally block. – Fabio Manzano Aug 29 '18 at 19:09
  • 1
    Hi Fabio, I am not programatically opening and closing the connection since i am using the jpa repository. Do i need to open/close explicitly in the code? – Magg Aug 29 '18 at 19:21
  • See if this helps: https://stackoverflow.com/questions/38672900/how-to-manage-database-connection-pool-in-spring-jpa – Fabio Manzano Aug 29 '18 at 19:25
  • Please share your job configuration as well as relevant parameters (connection pool size, thread pool size, etc). Are you using a multi-threaded step? – Mahmoud Ben Hassine Aug 30 '18 at 08:53
  • I created a demo project you can play with here: https://github.com/benas/sandbox/tree/master/so52083237. Try changing different parameters and see how it behaves. The p6spy log file shows that connections are reused (no resource leak), that one db connection is used for the entire chunk and not per record and that the connection pool is not exhausted even if there are more threads acquiring connections than the connexion pool size. Hope this helps in your performance issue investigation. – Mahmoud Ben Hassine Nov 27 '18 at 08:55

0 Answers0