Java – way to release a saturated connection pool

connection-poolingdatabaseibm-midrangejavaopen-esb

I'm working with open esb on a glassfish server.
We have a connection pool that works with an as400 Database.

Every couple of days we get this error:
Error in allocating a connection. Cause: In-use connections equal max-
pool-size and expired max-wait-time. Cannot allocate more connections

The best way to relief the cp is to restart the server.
We've also managed to set to another cp with the same attributes.

My questions is:
Is there a way to actively "tell" the cp to release all of its open connections?

Cheers,
Eran

Best Answer

Before doing so, figure out why the connections are not released properly. Sounds like there is a single place where this is forgotten (do you have all close() in finally clauses?).

I can strongly recommend Michael Nygards "Release It!" for techniques to make software production ready.

EDIT#1: If I understand your description correctly your backend programs go in MSGW in QSYSOPR which results in a hanging connection until the response is given which in your case is close to never. Is it an option to use a profile with a default reply of "C" which allows the fault to propagate to you as an exception?

Otherwise you may be able to set a timeout period for either the connections or for the whole server of 24 hours? Then at least the connections will eventually be closed. This solution does not scale though, but may make development easier.

Please note, it is also possible to have a separate surveillance thread which looks for MSGW's regularily and send them an answer automatically AFTER grabbing the call back stack for post mortem analysis.