简体   繁体   中英

Spring Boot JPA PostgreSQL Retry Policy

I have a spring-boot application which has a POST REST API which intern inserts data to Postgresql using JPA and Hikari. Since the Post requests huge in numbers, I am planning to implement Spring Retry on JPA built-in methods like save(),saveAll(),findAll() etc.,

My question is that is it good idea to do retry when there is time-out/connection failure from database ? (or) spring-boot or JPA already does this? if so please share the reference which mentions this.

The responsibility of giving you a healthy connection is that of the connection pool which constantly monitors the available connections. Before handing over a connection to you HikariCP tests the connection using either a test query or API ( in case the jdbc driver is JDBC4 compliant). More info here and here .

However once a connection is handed over and if there is a network issue while executing the query , the client would get an Execption. Is retry then a good idea ? I think for read queries this should be fine but for queries which changes data may not be good. For eg, your insert is successful but before the client gets the acknowledgement of transaction commit, a network issue occurs. So now the data is inserted. If you try again you will end up inserting twice.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM