Common Database Connection Pools

Source: Internet
Author: User
Tags connection pooling

Proxool, DBCP, and C3P0 are the three most common JDBC connection pooling technologies.

Introduction

C3p0

C3P0 is an open source JDBC connection pool that implements the data source and Jndi bindings, and supports the standard extensions of the JDBC3 specification and JDBC2. The open source projects that currently use it are hibernate,spring and so on.

C3P0 Required Jar:c3p0-0.9.2.1.jar Mchange-commons-java-0.2.3.4.jar

DBCP

DBCP (database connection pool), DB connection pool. is a Java Connection pool project on Apache and a connection pool component used by Tomcat.
2 packages are required to use DBCP: Commons-dbcp.jar, Commons-pool.jar because establishing a database connection is a very time-consuming and resource-intensive behavior, the connection pool is pre-established with the database to make some connections, put in memory, the application needs to establish a database connection directly to the connection pool to apply for a line, run out and then put back.

Proxool

Proxool is a Java database connection pooling technique. An open source project under SourceForge, this project provides a robust, easy-to-use connection pool, the most critical of which is the ability to monitor the connection pool, easy to use and easy to detect connection leaks.

Hibernate has officially announced that Proxool or C3P0 are recommended because there are too many bugs that no longer support DBCP.
In terms of performance and error rates, the Proxool is slightly better than the first two, but the user looks less.


The difference between C3P0 and DBCP
DBCP does not automatically reclaim idle connection functions
C3P0 has automatic recycle idle connection function

Configuration

1,C3P0 configuration:

    <!--configuring C3P0 Data Sources -    <BeanID= "DataSource"class= "Com.mchange.v2.c3p0.ComboPooledDataSource"Destroy-method= "Close">        < Propertyname= "Jdbcurl"value= "${jdbc.url}" />        < Propertyname= "Driverclass"value= "${jdbc.driverclassname}" />        < Propertyname= "User"value= "${jdbc.username}" />        < Propertyname= "Password"value= "${jdbc.password}" />        <!--the maximum number of connections that are kept in the connection pool. Default:15 -        < Propertyname= "Maxpoolsize"value= "+" />        <!--the minimum number of connections that are kept in the connection pool.  -        < Propertyname= "Minpoolsize"value= "1" />        <!--The number of connections obtained at initialization, and the value should be between Minpoolsize and Maxpoolsize. Default:3 -        < Propertyname= "Initialpoolsize"value= "Ten" />        <!--maximum idle time, unused in 60 seconds, the connection is discarded. If 0, it will never be discarded. default:0 -        < Propertyname= "MaxIdleTime"value= "+" />        <!--when the connection in the connection pool runs out, c3p0 the number of connections that are fetched at one time. Default:3 -        < Propertyname= "Acquireincrement"value= "5" />        <!--the standard parameters of JDBC to control the number of preparedstatements loaded within the data source. However, because the pre-cached statements belong to a single connection instead of the entire connection pool.          So setting this parameter takes into account a variety of factors. If both maxstatements and maxstatementsperconnection are 0, the cache is closed. default:0 -        < Propertyname= "Maxstatements"value= "0" />                 <!--Check for idle connections in all connection pools every 60 seconds. default:0 -        < Propertyname= "Idleconnectiontestperiod"value= "$" />                 <!--defines the number of repeated attempts to obtain a new connection from the database after a failure. Default:30 -        < Propertyname= "Acquireretryattempts"value= "+" />                <!--getting a connection failure will cause any thread that waits for the connection pool to get the connection to throw an exception. However, the data source is still valid and continues to try to get the connection the next time you call Getconnection (). If set to True, the data source will declare broken and permanently shut down after attempting to acquire a connection failure. Default:false -        < Propertyname= "Breakafteracquirefailure"value= "true" />                 <!--Please use it only when you need it because of high performance consumption. If set to true then the validity of each connection submission is officer. We recommend using methods such as Idleconnectiontestperiod or automatictesttable to improve the performance of your connectivity tests. Default:false -        < Propertyname= "Testconnectiononcheckout"value= "false" />            </Bean>

2,DBCP Configuration

 <!--Configuring DBCP Data Sources -      <BeanID= "DataSource2"Destroy-method= "Close"class= "Org.apache.commons.dbcp.BasicDataSource">        < Propertyname= "Driverclassname"value= "${jdbc.driverclassname}"/>        < Propertyname= "url"value= "${jdbc.url}"/>        < Propertyname= "username"value= "${jdbc.username}"/>        < Propertyname= "Password"value= "${jdbc.password}"/>        <!--number of connections created at pool startup -        < Propertyname= "InitialSize"value= "5"/>        <!--the maximum number of connections that can be allocated from the pool at the same time. When set to 0, it means no limit.  -        < Propertyname= "Maxactive"value= "+"/>        <!--the maximum number of idle connections that will not be released in the pool. When set to 0, it means no limit.  -        < Propertyname= "Maxidle"value= " the"/>        <!--The minimum number of connections that remain idle in the pool without creating a new connection.  -        < Propertyname= "Minidle"value= "3"/>        <!--set the auto-recycle timeout connection -          < Propertyname= "removeabandoned"value= "true" />        <!--Auto-Reclaim time-out (in seconds) -          < Propertyname= "Removeabandonedtimeout"value= "$"/>        <!--set the time-out error for printing a connection when the auto-recycle time-out connection -         < Propertyname= "logabandoned"value= "true"/>        <!--The wait time-out in milliseconds, before the exception is thrown, the maximum time the pool waits for the connection to be reclaimed (when no connection is available).  Set to 1 to indicate an infinite wait.  -          < Propertyname= "Maxwait"value= "+"/>        </Bean>

3,proxool Configuration

<BeanID= "DataSource"class= "Org.logicalcobwebs.proxool.ProxoolDataSource"Destroy-method= "Close">  < Propertyname= "Driver"value= "${db.driverclassname}"/>  < Propertyname= "Driverurl"value= "${db.url}"/> <!--The user name and password are written together before the call succeeds, or an invalid parameter error is reported -  < Propertyname= "User"value= "${db.user}"/>  < Propertyname= "Password"value= "${db.pass}"/>  < Propertyname= "Alias"value= "${db.alias}"/>  < Propertyname= "Housekeepingsleeptime"value= "90000"/>  < Propertyname= "Prototypecount"value= "5"/>  < Propertyname= "Maximumconnectioncount"value= "+"/>  < Propertyname= "Minimumconnectioncount"value= "Ten"/>  < Propertyname= "Trace"value= "true"/>  < Propertyname= "Verbose"value= "true"/></Bean>

Common Database Connection Pools

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.