I'm working with one legacy module's complicated part where multiple tables are being maintained by a Java process. It's using simple JDBC & prepared statements with Oracle. We are noticing frequent failure of this process with Connection Reset exception. Could anyone suggest how can we implement retry logic to re-establish the connectivity when its getting reset. Also can it be done through configeration, so we don't need to touch legacy code?
1 Answer
This happens when connection pool is not properly validated.
It's recommend to test before borrow connection from connection pool before use.
This is my typical Spring config, please adapt to your legacy java app:
spring.datasource.tomcat:
validation-query: SELECT 1 // test query
test-on-borrow: true // should test before borrowing from pool
validation-interval: 30000 // Validation interval, reduce number of tests
SELECT 1 FROM DUAL. If not valid, the pool throws it away and tries/creates another connection. Be sure to return the object to the pool after the query is complete to allow the pool to manage the connection. the pool handles the commit/close, not the query class.