Close DBCP connection on application exit

887 views Asked by At

In out app we use Apache DBCP connector for Oracle DB. But every 30 or 40 minutes we get connection size leak error.

Is there any way to close all connections from pool before app is exit?
e.g. write a method, which can get close event and in that method we can close connections safely.

2

There are 2 answers

0
Vineet Kasat On

In mysql there is a way to provide a timeout for sleeping connections (connections not closed properly). This helps a lot in cases where connections leak due to application not closing the connections properly.

There should be an alternative for the same in oracle as well.

4
Krzysztof Cichocki On

When you terminate your app, all the connections are freed after some particullary short time like few seconds. But if your app dosn't handle the closing connections it may not exit at all. You need to close any open connections after you use them in a finally block of try/catch statements.

if your app is a gui app, the JFrame will not exit by default, and not termiante your app.

try adding this invocation on your JFrame (if you use one) it will cause the app to exit permanently after you click the "X" to close the window;

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);