[C3p0] c3p0

Source: Internet
Author: User

C3p0 is an open-source JDBC connection pool that implements data source and JNDI binding and supports jdbc3 specifications and standard extensions of jdbc2. Currently, open-source projects using it include Hibernate and spring.

<C3p0-config>
<Default-config>
<! -- The number of connections that c3p0 obtains at the same time when connections in the connection pool are exhausted. Default: 3 -->
<Property name = "acquireincrement"> 3 </property>
<! -- Defines the number of repeated attempts after a new connection fails to be obtained from the database. Default: 30 -->
<Property name = "acquireretryattempts"> 30 </property>
<! -- Interval between two connections, in milliseconds. Default: 1000 -->
<Property name = "acquireretrydelay"> 1000 </property>
<! -- When the connection is closed, all uncommitted operations are rolled back by default. Default: false -->
<Property name = "autocommitonclose"> false </property>
<! -- C3p0 creates an empty table named test and uses its own query statement for testing. If this parameter is defined
The preferredtestquery attribute is ignored. You cannot perform any operation on this test table. It will only be used for c3p0 testing.
. Default: NULL -->
<Property name = "automatictesttable"> test </property>
<! -- Failed to obtain the connection will cause all threads waiting for the connection pool to obtain the connection to throw an exception. However, the data source is still valid.
Retained, and continue to get the connection when getconnection () is called the next time. If it is set to true
After the connection fails, the data source is declared disconnected and permanently closed. Default: false -->
<Property name = "breakafteracquirefailure"> false </property>
<! -- When the connection pool is used up, the client calls getconnection () and waits for the time to obtain the new connection.
Sqlexception. If it is set to 0, it will wait indefinitely. Unit: milliseconds. Default: 0 -->
<Property name = "checkouttimeout"> 100 </property>
<! -- Test the connection by implementing the connectiontester or queryconnectiontester class. The full path must be specified for the class name.
Default: COM. mchange. v2.c3p0. impl. defaultconnectiontester -->
<Property name = "connectiontesterclassname"> </property>
<! -- Specify the path of c3p0 libraries. If (usually like this) can be obtained locally, you do not need to set it. The default value is null.
Default: NULL -->
<Property name = "factoryclasslocation"> null </property>
<! -- Stronugly disrecommended. setting this to true may lead to subtle and bizarre bugs.
(Original document) an attribute that the author strongly recommends not to use -->
<Property name = "forceignoreunresolvedtransactions"> false </property>
<! -- Check all idle connections in the connection pool every 60 seconds. Default: 0 -->
<Property name = "idleconnectiontestperiod"> 60 </property>
<! -- Three connections are obtained during initialization. The value must be between minpoolsize and maxpoolsize. Default: 3 -->
<Property name = "initialpoolsize"> 3 </property>
<! -- Maximum idle time. connections are dropped if they are not used within 60 seconds. If it is 0, it will never be discarded. Default: 0 -->
<Property name = "maxidletime"> 60 </property>
<! -- The maximum number of connections retained in the connection pool. Default: 15 -->
<Property name = "maxpoolsize"> 15 </property>
<! -- JDBC standard parameter, used to control the number of preparedstatements loaded in the data source. However, due to the pre-Cache statements
Belongs to a single connection pool rather than the entire connection pool. Therefore, you need to consider many factors when setting this parameter.
If both maxstatements and maxstatementsperconnection are 0, the cache is disabled. Default: 0 -->
<Property name = "maxstatements"> 100 </property>
<! -- Maxstatementsperconnection defines the maximum number of statements cached for a single connection in the connection pool. Default: 0 -->
<Property name = "maxstatementsperconnection"> </property>
<! -- C3p0 is asynchronous, and slow JDBC operations are completed by helping the process. Scaling these operations can effectively improve performance
Multiple operations are executed simultaneously through multiple threads. Default: 3 -->
<Property name = "numhelperthreads"> 3 </property>
<! -- When the user calls getconnection (), the root user becomes the user who gets the connection. Used to connect a connection pool to non-c3p0
. Default: NULL -->
<Property name = "overridedefaultuser"> root </property>
<! -- This parameter corresponds to the overridedefaultuser parameter. Default: NULL -->
<Property name = "overridedefaultpassword"> password </property>
<! -- Password. Default: NULL -->
<Property name = "password"> </property>
<! -- Define the test statement executed for all connection tests. This significantly increases the testing speed when connection tests are used. Note:
The test table must exist at the initial data source. Default: NULL -->
<Property name = "preferredtestquery"> select ID from test where id = 1 </property>
<! -- The user can wait up to 300 seconds before modifying system configuration parameters. Default: 300 -->
<Property name = "propertycycle"> 300 </property>
<! -- Because of high performance consumption, use it only when needed. If set to true
Will verify its validity. We recommend that you use idleconnectiontestperiod or automatictesttable
To improve the connection test performance. Default: false -->
<Property name = "testconnectioncheckout"> false </property>
<! -- If it is set to true, the connection validity will be verified when the connection is obtained. Default: false -->
<Property name = "testconnectiononcheckin"> true </property>
<! -- User name. Default: NULL -->
<Property name = "user"> root </property>
Configuration in hibernate (Spring management:
<Bean id = "datasource" class = "com. mchange. v2.c3p0. combopooleddatasource" Destroy-method = "close">
<Property name = "driverclass"> <value> oracle. JDBC. Driver. oracledriver </value> </property>
<Property name = "jdbcurl"> <value> JDBC: oracle: thin :@ localhost: 1521: Test </value> </property>
<Property name = "user"> <value> Kay </value> </property>
<Property name = "password"> <value> root </value> </property>
<! -- The minimum number of connections retained in the connection pool. -->
<Property name = "minpoolsize" value = "10"/>
<! -- The maximum number of connections retained in the connection pool. Default: 15 -->
<Property name = "maxpoolsize" value = "100"/>
<! -- Maximum idle time. connections are discarded if they are not used within 1800 seconds. If it is 0, it will never be discarded. Default: 0 -->
<Property name = "maxidletime" value = "1800"/>
<! -- The number of connections that c3p0 obtains at the same time when connections in the connection pool are exhausted. Default: 3 -->
<Property name = "acquireincrement" value = "3"/>
<Property name = "maxstatements" value = "1000"/>
<Property name = "initialpoolsize" value = "10"/>
<! -- Check all idle connections in the connection pool every 60 seconds. Default: 0 -->
<Property name = "idleconnectiontestperiod" value = "60"/>
<! -- Defines the number of repeated attempts after a new connection fails to be obtained from the database. Default: 30 -->
<Property name = "acquireretryattempts" value = "30"/>
<Property name = "breakafteracquirefailure" value = "true"/>
<Property name = "testconnectiononcheckout" value = "false"/>
</Bean>
Edit the connection pool configuration in this section (taking hibernate as an example)
###########################
### C3p0 connection pool ###
###########################
# Hibernate. c3p0. max_size 2
# Hibernate. c3p0. min_size 2
# Hibernate. c3p0. Timeout 5000
# Hibernate. c3p0. max_statements 100
# Hibernate. c3p0. ID le_test_period 3000
# Hibernate. c3p0. acquire_increment 2
# Hibernate. c3p0. Validate false

Add the following configuration to the hibernate. cfg. xml file:
<! -- Maximum number of connections -->
<Property name = "hibernate. c3p0. max_size"> 20 </property>
<! -- Minimum connections -->
<Property name = "hibernate. c3p0. min_size"> 5 </property>
<! -- Get the connection timeout time. If the timeout value exceeds this time, an exception is thrown, in milliseconds. -->
<Property name = "hibernate. c3p0. Timeout"> 120 </property>
<! -- Maximum number of preparedstatement -->
<Property name = "hibernate. c3p0. max_statements"> 100 </property>
<! -- Check idle connections in the connection pool every 120 seconds. Unit: seconds -->
<Property name = "hibernate. c3p0. idle_test_period"> 120 </property>
<! -- When the connections in the connection pool are used up, c3p0 obtains the new connections -->
<Property name = "hibernate. c3p0. acquire_increment"> 2 </property>
<! -- Verify whether the connection is available every time -->
<Property name = "hibernate. c3p0. Validate"> true </property>
Difference between c3p0 and DBCP
DBCP does not automatically recycle idle connections.
C3p0 automatically recycles idle connections

Related Keywords:

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.