commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason Lea <>
Subject Re: [DBCP] Maintaining a minimum number of connections
Date Thu, 10 Apr 2003 23:07:51 GMT
Cindy Ballreich wrote:
> Vikas,
> Thanks for responding!
> Yes, I'm using MaxIdle, but it only controls the maximum number of connections that can
be idle. I'm concerned about the *minimum* number of connections. I've also set minEvictableIdleTimeMillis
to -1 which "should" cause connections never to time out (if I understand it's use correctly).
So it would seem that minEvictableIdleTimeMillis set not to time out, and MaxIdle set to keep
the number of idle connections to a reasonable number (say 10), I should always be able to
have at least 10 connections even if they're idle. This does not seem to be happening. The
connections were all closed when I tested them this morning. 
> Perhaps this is a moot issue since the production server will probably have enough accesses
to keep the connections from timing out, but I'm concerned that I can't keep these (idle)
connections open on my test server.
> Any other thoughts would be most welcome.

Are you checking the pool.getNumIdle() & pool.getNumActive() or are you 
looking at MySql's list of open connections?

If MySql shows no connections then it could be the wait_timeout setting 
in MySql is closing the idle connections.  MySql's log might show this.

If pool.getNumIdle() is 0, then this measures the number of objects in 
the pool (the actual connection may or may not be open).  The Evictor 
can check idle connections using the validation string to check if they 
are still open/working.  But as you have turned this off it won't be 
checking and throwing away objects.

 From what I can see, the functionality you want doesn't exist in DBCP. 
  It would be nice if you could set the minimum number of connections 
(active or idle) that should be open.  It would involve a couple of 
checks when objects are returned and in the Evictor, so that if the 
object is destroyed and the total number of connections is below the 
minimum then  a new object should be created and added to the pool.

You could compensate for this in your own application.  You could start 
your own monitoring thread that counts the total number of connections 
in the pool (pool.getNumIdle()+pool.getNumActive()).  If it is below 
your threshold you could call pool.addObject() until you have enough.

pool.addObject() comments says...

      * Create an object, and place it into the pool.
      * addObject() is useful for "pre-loading" a pool with idle objects.

The other problem is DBCP doesn't have commons-logging built in so it is 
hard to see if your objects are being evicted or not.

Jason Lea

View raw message