-1

We have a service that uses c3p0 library and we have added this property unreturnedConnectionTimeout to make sure unreturnedconnections are getting timed out but apparently c3p0 is not throwing exception but just printing exception stack trace when I put debugUnreturnedConnectionStackTraces property to true.

in this case our service thread which is waiting on c3p0 library waiting for connection forever because of no exception is thrown.

could u give us a solution how to handle this scenario?

1 Answers1

0

You are misunderstanding unreturnedConnectionTimeout.

There is no Exception for unreturnedConnectionTimeout to throw. If set properly, it has an effect only if you have leaked a Connection. Some client has checked out a Connection and failed to check it back in. No Exception has occurred. No client has been affected by this, except indirectly, as now there are fewer Connections available to check out. c3p0 just kills the unreturned Connection. There is no one to notify about that.

If you have clients that are waiting indefinitely for Connections, that sounds like you have a Connection leak that is not getting cleaned up by unreturnedConnectionTimeout, or more likely, you find it unacceptably long for Connections to wait as long as the timeout that you have set.

The thing that you should do is look at those stack traces that get logged, assuming you have debugUnreturnedConnectionStackTraces set to true. These stack traces do not represent Exceptions (even though they may print as "DEBUG" Exceptions) -- but they show you the code path that checked out the Connections that were never returned. Fix that, fix the Connection leak, and all your problems will go away. Look at how the Connection got checked out, find that in your code, and make sure that it's impossible that any Connection so checked out would not be closed in some finally block, or, much more easily post Java 7, via try-with-resources.

Steve Waldman
  • 13,689
  • 1
  • 35
  • 45