Configuration parameters for DBCP

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

TOMCATDE Configuration of DHCP
<resource driverclassname= "Com.microsoft.sqlserver.jdbc.SQLServerDriver"
Logabandoned= "true" maxactive= "maxidle=" 2 "maxwait=" Name= "System"
removeabandonedtimeout= "removeabandoned=" "true"
Password= "xx" type= "Javax.sql.DataSource"
Url= "Jdbc:sqlserver://127.0.0.1:1433;databasename=base"
Username= "sa"/>
Among the
Logabandoned= "true" removeabandoned= "true" removeabandonedtimeout= "60"
is used to configure the database to automatically connect after disconnecting.


The database connection pool establishes several connections that are required at startup and remains connected.
But when the database service is stopped, these connections are interrupted by external factors.
Optimized configuration information on the Web:
<bean id= "DataSource" class= "Org.apache.commons.dbcp.BasicDataSource" destroy-method= "Close" >
<property name= "Driverclassname" value= "${db.driverclassname}"/>
<property name= "url" value= "${db.url}"/>
<property name= "username" value= "${db.username}"/>
<property name= "Password" value= "${db.password}"/>
<!--initialsize: Initialize Connection--
<property name= "InitialSize" value= "5"/>
<!--maxidle: Maximum idle connection--
<property name= "Maxidle" value= "ten"/>
<!--minidle: Minimum idle connection--
<property name= "Minidle" value= "5"/>
<!--maxactive: Maximum number of connections--
<property name= "maxactive" value= "/>"
<!--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 6000 milliseconds/1000 equals 60 seconds--
<property name= "maxwait" value= "/>"
<property name= "Validationquery" >
<value>select 1</value>
</property>
<property name= "Testonborrow" >
<value>true</value>
</property>
</bean>

DBCP configuration Chinese version, from Apache official documents
Please see http://commons.apache.org/dbcp/configuration.html in the original.

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.

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.