Assuming I have the following code:
try {
//dao.querier behind the Scenes is using
//A Hibernate query with C3p0
List<?> newItems = dao.querier(true);
} catch (Exception e) {
e.printStackTrace();
}
Where the call to the method dao.querier
uses C3p0 and Hibernate. Being configured with the property unreturnedConnectionTimeout:
unreturnedConnectionTimeout=300
When I do have a connection that did not return to the Pool, the c3p0 says - “java.lang.Exception: DEBUG ONLY: Overdue resource check-out stack trace”.
Is this exception caught by the catch block in my code snippet. By debugging my application, it seems that the answer is NO. Is there a way I could caught that exception?
No, you could not have caught the Exception. The "Exception" you are seeing was never thrown. It was generated by debugUnreturnedConnectionStackTraces and then asked to dump it stack trace, in order to show you the code path that leaked the Connection.
unreturnedConnectionTimeout
exists to close()
Connections that have leaked (and to help you fix the leaks). Those Connections should be no longer accessible within any stack or within any try/catch block. If you set unreturnedConnectionTimeout
to a value that is too small, so that Connections are closed due to the setting while the application is still using them, you will see ordinary Exceptions when your application tries to work with the Connections after they have been closed.