views:

234

answers:

3

I am using Apache DBCP with JNDI in my tomcat container to pool connections to a mysql database. Everything works fine but a problem i am seeing is that once a pconnection is pooled it is never released. So after a load spike connection sit their forever sleeping. Is their a way to shrink the pool through context.xml parameters? here is my ocnfiguration:

  defaultAutoCommit="false"
  defaultTransactionIsolation="REPEATABLE_READ"
  auth="Container"
  type="javax.sql.DataSource"
  logAbandoned="true" 
     removeAbandoned="true"
  removeAbandonedTimeout="300" 
  maxActive="-1"
  initialSize="15"
  maxIdle="10"
  maxWait="10000" 
  username="user"
  password="password"
  driverClassName="com.mysql.jdbc.Driver"
  url="jdbc:mysql://localhost/mydb"/>
+2  A: 

Try to set minEvictableIdleTimeMillis to lower value than its default, which is 1000*60*30.

Adeel Ansari
you also need to set the following properties: testWhileIdle, timeBetweenEvictionRunsMillis, validationQuery
Igor Zelaya
+1  A: 

try to use c3p0 connection pool`~~

Aaron
Indeed its better than DBCP, at the moment at least. And the parameter names are easy to understand. Your post is not trying to solve the issue at hand :). Anyways +1
Adeel Ansari
+1  A: 

In comparable situations I've used Tomcat's JMX adapter to tweak the settings of the connection pool. This can be used both, to increase and to decrease thesize of the pool. It is therefore a good idea to enable JMX remote access to the servlet container at least in production environments, just to have some chance to react on exceptional operational situations.

Ralf Edmund