日期:2014-05-16 浏览次数:20382 次
【本文如需转载,请注明作者及出处】
?
I think a lot of people have misunderstanding about DBCP. What makes them think so?
Cause' DBCP seems don't want to release database connection after use. Finally, all available connections got exhausted, and our application runs out of services.
DBCP is weak and can not bear production pressures, according to them. It’s worse that there are a lot of guys on the internet said so.
In fact, DBCP can absolutely take the job!
Firstly, its release number has reached 1.2.2. Base on the Apache Version Numbering Project's theory, any products whose version number has evolved up to 1, it is eligible to be used in production environment.
Second, I've run into such problem from my previous working experience, and my ex-colleague and I have made extensive tests on various Connection Pool products, such as Proxool, c3p0 and DBCP.
Result shows that DBCP behaves very well not only at responsiveness, stability, but also at performance. Once the network resume, it auto-reconnects instantly even after more than 8 hours network disconnection.
Third, I do the test again, but this time it’s only between DBCP and c3p0. The test starts from running 3000?to 5000 threads, which infinitely?execute a query lasting at least 1 second. Effort have been made to let DBCP and C3p0 start equally, like the same initial pool size 0, the same max pool size and the same time out, etc.
?
?
Finally, I try to give you a detail introduction on the configurations of DBCP, focusing on the important parameters.
?
?All information comes from http://commons.apache.org/dbcp/configuration.html
Part1, Besides the Normal parameters:
username????????????????????????? ?The connection username to be passed to our JDBC driver to establish a connection.
password???????????????????????? ? The connection password to be passed to our JDBC driver to establish a connection.
url???????????????????????????????????????The connection URL to be passed to our JDBC driver to establish a connection.
driverClassName??????????????? The fully qualified Java class name of the JDBC driver to be used.
Part2, the following are related to performances:
initialSize??????????????????????????? The initial number of connections that are created when the pool is started.
maxActive?????????????????????????? The maximum number of active connections that can be allocated from this pool at the same time, or non-positive for no limit.
maxIdle??????????????????????????????The maximum number of connections that can remain idle in the pool, without extra ones being released, or negative for no limit.
minIdle???????????????????????????????The minimum number of connections that can remain idle in the pool, without extra ones being created, or zero to create none.
maxWait??????????????????????????? ?The maximum number of milliseconds that the pool will wait (when there are no available connections) for a connection to be returned before throwing an exception, or -1 to wait indefinitely.
poolPreparedStatements??? Enable prepared statement pooling for this pool.
maxOpenPreparedStatements? The maximum number of open statements that can be allocated from the statement pool at the same time, or zero for no limit. <