commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From commons-...@jakarta.apache.org
Subject [Jakarta Commons Wiki] New: DBCP
Date Thu, 20 May 2004 11:39:48 GMT
   Date: 2004-05-20T04:39:47
   Editor: DirkVerbeeck <dirkv@apache.org>
   Wiki: Jakarta Commons Wiki
   Page: DBCP
   URL: http://wiki.apache.org/jakarta-commons/DBCP

   Moved page from old wiki

New Page:

Is this project still active or have they just not released anything in an excessive period
of time?

DBCP is still active.  It is an active area of discussion right now on the commons-dev mailing
list, and has had a number of recent commits.

----

What is the best way, ASIDE from running a query against the DB, to be sure that the connection
is still valid when it is retrieved from the pool?

1) this question may be better posed on commons-user or commons-dev.

2) how would you do this without a pool?  I.e., what is the best way aside from running a
query to be sure that a connection is still valid when returned from DriverManager/DataSource.getConnection?

----

When upgrading from DBCP 1.0 to DBCP 1.1 you can encounter the following issue (reported on
commons-user): 
We are accessing mainframe data using a JDBC
driver, but it is not truly a database.  Specifically, the setAutoCommit and
setReadOnly Connection methods fail.  Version 1.0 of DBCP silently discarded
these errors and allowed the connections to be created and used anyway.
Version 1.1 of activateObject surfaces these exceptions and fails to create
new connections in the pool.
(solution: use custom activateObject method)

----

Q: I see in the javadocs that AbandonedConnectionPool was deprecated (DBCP 1.1). What replaced
it?

A: The original reason for deprecation was the danger in reusing a abandoned connection without
knowing if it is safe to do so. There was a discussion about it in april. Some people wanted
to remove it completely.

I took a different approach. In 1.1 an abandoned connection will not be reused but closed
(and a new one created).
The classes remained deprecated because I think the AbandonedPool should move to the pool
package (and made more generic/safe).

The abandoned connection feature on BasicDataSource will remain supported in one form or another.
I'm not using it on my tomcat production configurations but there are junit tests to make
sure everything works.

So if you are using the Abandoned* classes directly then it is possible you are affected by
a future refactoring (we will try to remain compatible if possible of course). If you use
BasicDataSource then you can be sure the feature will remain.

----

Q: When using DBCP what parameter needs to be set on the ObjectPool so that a
minimum number of connections are created when the pool instance is created
? I thought the setMinIdle() does this, but doesn't look so. 

A: You can setMinIdle() to always have a minium amount of idle connection in the pool. (not
only at the start of the pool but the whole time)
The minIdle check is done in the evictor thread so timeBetweenEvictionRunsMillis  has to be
set to a non negative-value. (you can optionally turn off the eviction by setting  numTestsPerEvictionRun
to zero or just set minEvictableIdleTimeMillis very high).

A more simple way to create a number of connections at startup is to use the pool.addObject()
method.
(add the following after creating the PoolableConnectionFactory)

for (int i=0 ; i<initialsize ; i++) {
   connectionPool.addObject()
}

----

Q: <nowiki>Does the current 1.1 release support the poolable/caching of PreparedStatements.
I noted that the PoolableConnectionFactory can take a KeyedObjectPoolFactory as a statement
pool factory. But there is not concrete implementation for the KeyedPoolableObjectFactory
which is required when creating a GenericKeyedObjectPoolFactory. If I pass in a null as shown
in the examples, does it cache prepared statements or should I do that in local objects?</nowiki>

A: ??

----

Q: Where do I get a concrete example of PerUserPoolDataSource? How do we use it in a situation
where multiple pools are required for different modules of a project and their properties
differ on the database transactional load?

----

Here's a little diagram showing what datastructure DBCP sets up and how that datastructure
is used in case the DriverManager is 
employed to obtain Drivers at runtime. Please send any corrections (for now) to d.tonhofer@m-plify.com.


  * http://rei1.m-plify.net/Apache_DBCP/Apache_DBCP_Structure.pdf 
  * http://rei1.m-plify.net/Apache_DBCP/Apache_DBCP_Structure.vsd 

There is also a *PNG* image but I don't include the link here because the Wiki includes it
directly and it's a tad large.


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message