dbcp| C3P0 parameter explanation

Source: Internet
Author: User
Tags connection pooling stack trace time in milliseconds

1.<!--Data source 1--
2. <bean id= "DataSource"
3. class= "Org.apache.commons.dbcp.BasicDataSource"
4. Destroy-method= "Close" >
5. <property name= "Driverclassname" value= "Com.mysql.jdbc.Driver"/>
6. <property name= "url" value= "jdbc:mysql://192.168.0.109:3306/test?useunicode=true&characterencoding= UTF-8 "/>
7. <property name= "username" value= "root"/>
8. <property name= "password" value= "root"/>
9. <!--maxactive: Maximum number of connections--
<property name= "maxactive" value= "/>"
<!--minidle: Minimum idle connection--
<property name= "Minidle" value= "5"/>
<!--maxidle: Maximum idle connection--
<property name= "Maxidle" value= "/>"
<!--initialsize: Initialize Connection--
<property name= "initialsize" value= "/>"
<!--If the connection is printed when it is compromised.
<property name= "logabandoned" value= "true"/>
<!--removeabandoned: Whether the auto-recycle timeout is connected--
<property name= "removeabandoned" value= "true"/>
<!--removeabandonedtimeout: Time-out (in seconds)-
<property name= "removeabandonedtimeout" value= "/>"
<!--maxwait: Timeout wait time in milliseconds--
<property name= "maxwait" value= "/>"
<!--the time value, in milliseconds, that sleeps during the idle connection collector thread run. -
<property name= "Timebetweenevictionrunsmillis" value= "10000"/>
<!--the number of connections that are checked at run time for each idle connection collector thread (if any)-
<property name= "Numtestsperevictionrun" value= "/>"
<!--1000 * 60 * 30 connections remain idle in the pool and not be idle connection to the collector thread--
<property name= "Minevictableidletimemillis" value= "10000"/>
<property name= "Validationquery" value= "Select Now () from DUAL"/>
</bean>

Parameter description
Username The user name passed to the JDBC driver to establish the connection
Password passed to the JDBC-driven password used to establish the connection
URL passed to the JDBC-driven URL used to establish the connection
Full valid Java class name for the JDBC driver used by driverclassname
ConnectionProperties The connection parameters that are sent to the JDBC driver when a new connection is established,
The format must be [Propertyname=property;] *
Note: The parameter User/password will be explicitly passed, so it does not need to be included here.

Parameter Default value description
Defaultautocommit True The default Auto-commit state of connections created by the connection pool
Defaultreadonly Driver The default read-only state of the connection created by the default connection pool.
The Setreadonly method will not be called if it is not set. (Some drivers do not support read-only mode, such as Informix)
Defaulttransactionisolation Driver The default transactionisolation state of the connection created by the default connection pool.
One of the following lists: (Reference Javadoc)

* NONE
* read_committed
* read_uncommitted
* Repeatable_read
* SERIALIZABLE

Defaultcatalog The default catalog for connections created by the connection pool

Parameter Default value description
InitialSize 0 Initializing connections: Number of initial connections created when connection pooling starts, support after version 1.2
Maxactive 8 Maximum active connections: The maximum number of active connections that the connection pool can allocate at the same time,
If set to non-positive, it means no limit
Maxidle 8 Maximum idle connection: the maximum number of connections allowed to remain idle in the connection pool, and the excess idle connection will be released.
If set to a negative number means no limit
Minidle 0 Minimum idle connection: the minimum number of connections allowed to remain idle in the connection pool, below which a new connection is created.
Not created if set to 0
maxwait Infinite Maximum wait time: The maximum time (in milliseconds) that the connection pool waits for a connection to be returned when there is no available connection.
An exception is thrown if the time is exceeded, and if set to-1 means infinite wait

Parameter Default value description
Validationquery SQL query, used to verify connections taken from the connection pool before the connection is returned to the caller. If specified,
The query must be a SQL select and must return at least one row of records
Testonborrow True Indicates whether the test is performed before the connection is removed from the pool, and if the test fails,
Remove the connection from the pool and try to remove the other.
Note: When set to True, the Validationquery parameter must be set to a non-empty string if it is to take effect
Testonreturn False Indicates whether the test is made before being returned to the pool
Note: When set to True, the Validationquery parameter must be set to a non-empty string if it is to take effect
Testwhileidle False Indicates whether the connection was verified by the idle connection collector, if any. If the detection fails,
The connection is removed from the pool.
Note: When set to True, the Validationquery parameter must be set to a non-empty string if it is to take effect
TimeBetweenEvictionRunsMillis-1 the time value, in milliseconds, that sleeps while the idle connection collector thread is running.
If set to non-positive, the idle connection collector thread is not run
Numtestsperevictionrun 3 Number of connections checked at run time for each idle connection collector thread (if any)
Minevictableidletimemillis 1000 * 60 * 30 connections remain idle in the pool without being idle to the garbage collector thread
(if any) the minimum time value of the collection, in milliseconds

Parameter Default value description
Poolpreparedstatements false to open pool prepared statement pool function
Maxopenpreparedstatements does not limit the maximum number of open statements that the statement pool can allocate at the same time,
If set to 0, no limit


The preparedstatements pool can be opened here. When turned on, a statement pool is created for each connection,
And the preparedstatements created by the following method will be cached:
* Public PreparedStatement preparestatement (String sql)
* Public PreparedStatement preparestatement (String sql, int resultsettype, int resultsetconcurrency)
Note: Confirm that the connection has remaining resources left to other statement
Parameter Default value description
Accesstounderlyingconnectionallowed false to control whether Poolguard allows access to the underlying connection


If allowed, you can use the following method to obtain the underlying connection:
Connection conn = Ds.getconnection ();
Connection Dconn = ((delegatingconnection) conn). Getinnermostdelegate ();
...
Conn.close ();

Default false does not turn on, this is a potentially dangerous feature, improper coding can cause damage.
(Close the underlying connection or continue to use it if the daemon connection is closed). Please use it carefully,
and is used only when direct access to specific features of the drive is required.
Note: Do not close the underlying connection, only the previous one.
Parameter Default value description
Removeabandoned false to flag whether to remove compromised connections if they exceed the removeabandonedtimout limit.
If set to True, the connection is considered to be compromised and can be deleted if the idle time exceeds removeabandonedtimeout.
Set to True to repair the database connection for poorly written programs that do not have the connection closed.
Removeabandonedtimeout 300 The time-out value of a leaked connection that can be deleted, in seconds
Logabandoned false to mark whether the program's stack traces log is printed when the statement or connection is compromised.
The leaked statements and connected logs are added on each connection to open or generate a new statement,
Because a stack trace needs to be generated.


If "removeabandoned" is turned on, the connection may be reclaimed by the pool when it is considered compromised. This mechanism in (Getnumidle () < 2)
and (Getnumactive () > Getmaxactive ()-3) are triggered.
For example, "removeabandoned" can be triggered when an active connection is 18 and an idle connection of 1 is maxactive=20.
However, the active connection is deleted only if it has not been used for more than "Removeabandonedtimeout", and the default is 300 seconds.
Travels in the ResultSet are not counted as being used.

<c3p0-config>
<default-config>
<!--c3p0 The number of connections that are fetched at the same time when the connection in the connection pool is exhausted. Default:3--
<property name= "Acquireincrement" >3</property>

<!--defines the number of repeated attempts to obtain a new connection from the database after a failure. Default:30--
<property name= "Acquireretryattempts" >30</property>

<!--the interval between two connections, in milliseconds. default:1000--
<property name= "Acquireretrydelay" >1000</property>

< All uncommitted actions are rolled back by default when the connection is closed!--. Default:false--
<property name= "Autocommitonclose" >false</property>

<!--C3P0 will build a blank table named Test and test it with its own query statement. If this parameter is defined, then
Property Preferredtestquery will be ignored. You cannot do anything on this test sheet, it will be for C3P0 testing only
Use. Default:null-->
<property name= "Automatictesttable" >Test</property>

<!--getting a connection failure will cause any thread that waits for the connection pool to get the connection to throw an exception. But the data source is still valid
Reserved and continue trying to get the connection the next time you call Getconnection (). If set to true, then try to
When a connection failure is obtained, the data source declares that it has been fractured and closed permanently. Default:false-->
<property name= "Breakafteracquirefailure" >false</property>

<!--the time when the client calls getconnection () after the connection pool has run out, and then throws
SQLException, if set to 0, waits indefinitely. Unit milliseconds. Default:0--
<property name= "Checkouttimeout" >100</property>

<!--test the connection by implementing a class of Connectiontester or Queryconnectiontester. The class name needs to be set to the full path.
Default:com.mchange.v2.c3p0.impl.defaultconnectiontester-->
<property name= "Connectiontesterclassname" ></property>

<!--Specify the path to the C3P0 libraries, if (as is often the case) you can get it locally without setting, default null
Default:null-->
<property name= "Factoryclasslocation" >null</property>

<!--strongly disrecommended. Setting this to true may leads to subtle and bizarre bugs.
Author strongly recommends not to use a property--
<property name= "Forceignoreunresolvedtransactions" >false</property>

<!--check for idle connections in all connection pools every 60 seconds. Default:0--
<property name= "Idleconnectiontestperiod" >60</property>

<!--get three connections when initializing, the value should be between Minpoolsize and Maxpoolsize. Default:3--
<property name= "Initialpoolsize" >3</property>

<!--maximum idle time, unused in 60 seconds, the connection is discarded. If 0, it will never be discarded. Default:0--
<property name= "MaxIdleTime" >60</property>

<!--The maximum number of connections that are kept in the connection pool. Default:15--
<property name= "Maxpoolsize" >15</property>

<!--the standard parameters of JDBC to control the number of preparedstatements loaded within the data source. But due to the statements of the pre-cache
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-->
<property name= "Maxstatements" >100</property>

<!--maxstatementsperconnection defines the maximum number of cache statements that a single connection in a connection pool has. Default:0--
<property name= "Maxstatementsperconnection" ></property>

<!--C3P0 is asynchronous, and slow JDBC operations are done through the help process. Extending these operations can effectively improve performance
Multiple operations are performed at the same time through multithreading. Default:3-->
<property name= "Numhelperthreads" >3</property>

<!--when a user calls getconnection () to make the root user the user who is going to get the connection. Primarily for connection pooling connections non-C3P0
Data source. Default:null-->
<property name= "Overridedefaultuser" >root</property>

<!--a parameter that corresponds to the Overridedefaultuser parameter. Default:null-->
<property name= "Overridedefaultpassword" >password</property>

<!--password. Default:null-->
<property name= "Password" ></property>

<!--define test statements that are executed by all connection tests. This one significantly improves the test speed in the case of connection testing. Attention:
The test table must exist at the time of the initial data source. Default:null-->
<property name= "preferredtestquery" >select ID from test where id=1</property>

<!--the user to wait up to 300 seconds before modifying the system configuration parameters. DEFAULT:300--
<property name= "Propertycycle" >300</property>

<!--use it only when you need it, due to its high performance consumption. If set to true then each connection commits the
Officer the validity of the test. It is recommended to use Idleconnectiontestperiod or automatictesttable
and other methods to improve the performance of the connection test. Default:false--
<property name= "Testconnectiononcheckout" >false</property>

<!--If set to true then officer the validity of the connection while the connection is made. Default:false--
<property name= "Testconnectiononcheckin" >true</property>

<!--user name. Default:null-->
<property name= "User" >root</property>

<!--earlier versions of C3P0 use dynamic reflection proxies for JDBC interfaces. In the case of a wide range of previous versions, this parameter
Allows the user to revert to the dynamic reflection agent to resolve an unstable failure. The newest non-reflection agent is faster and has started
Widely used, so this parameter may not be useful. Now the original dynamic reflection and the new non-reflection agent are
Supported, but possible future versions may not support dynamic reflection agents. Default:false-->
<property name= "Usestraditionalreflectiveproxies" >false</property>

<property name= "Automatictesttable" >con_test</property>
<property name= "Checkouttimeout" >30000</property>
<property name= "Idleconnectiontestperiod" >30</property>
<property name= "Initialpoolsize" >10</property>
<property name= "MaxIdleTime" >30</property>
<property name= "Maxpoolsize" >25</property>
<property name= "Minpoolsize" >10</property>
<property name= "Maxstatements" >0</property>
<user-overrides user= "Swaldman" >
</user-overrides>
</default-config>
<named-config name= "Dumbtestconfig" >
<property name= "Maxstatements" >200</property>
<user-overrides user= "Poop" >
<property name= "Maxstatements" >300</property>
</user-overrides>
</named-config>
</c3p0-config>

dbcp| C3P0 parameter explanation

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.