0

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?

4
  • 2
    Use 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. Commented May 3, 2018 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? Commented May 3, 2018 at 19:01
  • Are you using any type of connection pooling ? Commented May 3, 2018 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. Commented May 3, 2018 at 19:35

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.