Friday, April 2, 2010

Solution for Connectionpool Timeout Exception

Exception: Cannot get a connection, pool error Timeout

Timeout error will be raised when the DB connection is unavailable from the pool due to the reason of not properly closed connection. So in web application connection need to be closed explicitly. Also following configuration in resource (Context.xml) changes will fix the issue also helps in debugging the code.

To configure a DBCP DataSource so that abandoned dB connections are removed and recycled add the following attribute to the Resource configuration for your DBCP DataSource:
            removeAbandoned="true"

When available db connections run low DBCP will recover and recycle any abandoned dB connections it finds. The default is false.
Use the removeAbandonedTimeout attribute to set the number of seconds a dB connection has been idle before it is considered abandoned.
            removeAbandonedTimeout="60"

The default timeout for removing abandoned connections is 300 seconds.
The logAbandoned attribute can be set to true if you want DBCP to log a stack trace of the code which abandoned the dB connection resources.
            logAbandoned="true"
The default is false.

Reference:
http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html

No comments:

Post a Comment