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?
Asked
Active
Viewed 312 times
0
-
2Use a connection pool and enable validation. When a connection is borrowed from the pool it is tested to make sure it is valid. Validation should be a simple query such as `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. – Andrew S May 03 '18 at 18:54
-
@AndrewS Thanks, As I mentioned its a legacy code and looking for a very minimal change, can re-connection be achieved by config change? Also this code is handling many tables, for example if connection reset occurred at half way of processing, how can the re-try connection can be triggered? – Suvadip May 03 '18 at 19:01
-
Are you using any type of connection pooling ? – Shubham Kadlag May 03 '18 at 19:22
-
What is the exact exception you're getting? Also Oracle version might be relevant and whether it's a high availability / RAC installation. – Mick Mnemonic May 03 '18 at 19:35
1 Answers
1
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

Mạnh Quyết Nguyễn
- 17,677
- 1
- 23
- 51