Open source JDBC Connection pool dbcp and c3p0 configuration (RPM)

Source: Internet
Author: User

now Tomcat is using the default Apache DBCP connection pool for the company framework. This kind of connection pool is from the Noble Apache Foundation. But the word of mouth is not very good, in the new version of Hibernate has abandoned the support for DBCP, replaced by C3P0. At first I also had hope for DBCP, plus various parameter settings, but none were valid. Later changed on the C3P0, using its testconnectiononcheckout, testconnectiononcheckin parameter configuration after a sword sealed the throat solved the problem. (Note: This method will actually bring some performance loss)

One, dbcp and C3P0 connection pool Common configuration parameters list
 
dbcp Configuration
<bean id= "Hospitaldatasource" class= "Org.apache.commons.dbcp.BasicDataSource" destroy-method= "Close" >
<property name= "Driverclassname" ><value>${jdbchospital.driverclassname}</value></ Property>
<property name= "url" ><value>${jdbcHospital.url}</value></property>
<property name= "username" ><value>${jdbcHospital.username}</value></property>
<property name= "password" ><value>${jdbcHospital.password}</value></property>
<property name= "InitialSize" value= "ten"/>
<property name= "maxactive" value= "/> "
<property name= "maxidle" value= "/> "
<property name= "Minidle" value= "ten"/>
<property name= "logabandoned" value= "true"/>
<property name= "removeabandoned" value= "true"/>
<property name= "removeabandonedtimeout" value= "/> "
<property name= "maxwait" value= "/> "
</bean>
Defaultautocommit: Sets whether the connection returned from the data source takes the auto-commit mechanism, and the default value is true;
defaultreadonly: Sets whether the data source can only perform read-only operations, the default value is false;
maxactive: Maximum Connection database connection number, set to 0 o'clock, indicating no limit;
Maxidle: The maximum number of waiting connections, set to 0 o'clock, indicates no limit;
maxwait: The maximum number of seconds to wait, in milliseconds, over time will be reported error message;
validationquery: A query SQL statement that verifies that a connection is successful, the SQL statement must return at least one row of data, as you can simply set to: "SELECT COUNT (*) from user";
removeabandoned: Whether self-interruption, default is false;
removeabandonedtimeout: The data connection is automatically disconnected after a few seconds, and the value is provided when removeabandoned is true;
logabandoned: If the interrupt event is logged, the default is false;

c3p0 Configuration
<bean id= "Hospitaldatasource" class= "Com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method= "Close" >
<property name= "Driverclass" value= "${jdbchospital.driverclassname}"/>
<property name= "Jdbcurl" value= "${jdbchospital.url}"/>
<property name= "user" value= "${jdbchospital.username}"/>
<property name= "password" value= "${jdbchospital.password}"/>
<property name= "maxpoolsize" value= "/> "
<property name= "minpoolsize" value= "ten"/>
<property name= "initialpoolsize" value= "ten"/>
<property name= "Breakafteracquirefailure" value= "true"/>
<property name= "Testconnectiononcheckout" value= "true"/>
<property name= "Testconnectiononcheckin" value= "true"/>
</bean>
c3p0 has richer configuration properties than DBCP, which allow for a variety of effective control over the data source:
acquireincrement: When a connection in the connection pool is exhausted, C3P0 creates the number of new connections at once;
acquireretryattempts: Defines the number of repeated attempts to obtain a new connection from the database, by default;
Acquireretrydelay: Two times the interval in the connection, in milliseconds, the default is;
Autocommitonclose: All uncommitted operations are rolled back by default when the connection is closed. The default is false;
Automatictesttable:c3p0 will build an empty table named Test and test it with its own query statement. If this parameter is defined, then the property preferredtestquery is ignored. You cannot take any action on this test table, it will be used in the C3P0 test, default is null;
breakafteracquirefailure: Getting a connection failure will cause all threads waiting 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. The default is false;
Checkouttimeout: When the connection pool is exhausted, the client calls getconnection () to wait for a new connection, and then throws SqlException after the timeout, and waits indefinitely if set to 0. Unit milliseconds, default is 0;
connectiontesterclassname: To test a connection by implementing a class of Connectiontester or Queryconnectiontester, the class name needs to be set to the fully qualified name. The default is Com.mchange.v2.C3P0.impl.DefaultConnectionTester;
Idleconnectiontestperiod: How many seconds to check the idle connection in all connection pools, the default is 0 means no check;
Initialpoolsize: The number of connections created at initialization should be taken between Minpoolsize and Maxpoolsize. The default is 3;
maxidletime: Maximum idle time, the connection over idle time will be discarded. 0 or negative numbers will never be discarded. The default is 0;
maxpoolsize: The maximum number of connections that are kept in the connection pool. default is;
MAXSTATEMENTS:JDBC standard parameter to control the number of PreparedStatement loaded within the data source. However, because the pre-cached statement belong to a single connection instead of the entire connection pool. So setting this parameter takes many factors into account, and if both maxstatements and maxstatementsperconnection are 0, the cache is closed. The default is 0;
maxstatementsperconnection: The maximum number of cache statement that a single connection in a connection pool has. The default is 0;
numhelperthreads:c3p0 are asynchronous operations, and slow JDBC operations are done by helping the process. Extending these operations can effectively improve performance, and multiple operations are performed simultaneously through multithreading. The default is 3;
preferredtestquery: Defines test statements that are executed by all connection tests. This parameter can significantly improve the test speed when using the connection test. The test table must exist at the time of the initial data source. default is null;
propertycycle: The maximum number of seconds a user waits before modifying system configuration parameters. default is;
Testconnectiononcheckout: 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. It is recommended to use Idleconnectiontestperiod or automatictesttable
and other methods to improve the performance of the connection test. The default is false;
Testconnectiononcheckin: If set to true then the validity of the officer connection is obtained while the connection is made. The default is False.

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.