0

What options are available in Java to timeout a database connection at a specific period of time?

For example, an application creates a database connection from a data source, then it executes a SQL query which might take 5,15 or even over 60 minutes to return results. This behavior is causing other issues.

What I am asking is regarding this scenario, how can we have the application make the database call and after 15 minutes if the query is still running, then stop query, close connection and continue with the application execution?

Thank you

1

1 Answer 1

2

This can be achieved by setting transaction timeout. Exception will be thrown if transaction exceeds the preconfigured timeout.

The transaction timeout configuration depends on your environment but it is easy to find instraction for each application server or framework. For example in Spring this can be controlled by attribute of annotation @Transactional (documentation link).

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Alex. Will give this a whirl. Sounds like this should solve this issue.

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.