TOMCAT7 enhanced the Database connection pooling feature with the following connection pool configuration:
<resource name= "JDBC/ECP" auth= "Container" type= "Javax.sql.DataSource" maxactive= "+" maxidle= "maxwait" = "10000" username= "Xm_db_portal" factory= "Org.apache.tomcat.jdbc.pool.DataSourceFactory" password= "xm_db_portal20 " driverclassname=" Oracle.jdbc.driver.OracleDriver "testonborrow=" true "testwhileidle=" false "testonreturn=" True
validationquery= "Select 1 from Dual" url= ""/>
Modify the URL property values according to the use of MySQL and Oracle.
Testonborrow is set to true. Whenever data is taken from the connection pool, the connection is judged to be valid. You can prevent the back-end database from being disconnected, and the Tomcat client database pool is not fractured. You can also set the Maxwait property (connection time-out) < database connection time-out.
Maxactive: Maximum number of active database connections
Maxidle: Maximum number of idle database connections. The internal Tomcat will also be released at timed idle connection detection. You can set the idle connection pool time-out time, not commonly used. Please refer to the Tomcat official documentation.
Factory: Connection Pool Factory
C3P0 is also a very good connection pool, its configuration in Tomcat is as follows:
<resource name= "JDBC/ECP" auth= "Container" type= "Com.mchange.v2.c3p0.ComboPooledDataSource" factory= " Org.apache.naming.factory.BeanFactory " driverclass=" Oracle.jdbc.OracleDriver " jdbcurl=" jdbc:oracle: thin:@ (description= (address_list= (address= (protocol=tcp) (host=192.168.28.50)) (port=1521) (ADDRESS= (host=192.168.28.51) (port=1521))) (Connect_data= (SERVICE_NAME=CHNDB))) " user=" xm_db_portal "password= " Xm_db_portal20 "minpoolsize=", "maxpoolsize=", " maxidletime=" acquireincrement= " ten " maxstatements= "0" initialpoolsize= "ten" idleconnectiontestperiod= " acquireretryattempts=" 30 " acquireretrydelay= "" testconnectiononcheckin= "false" breakafteracquirefailure= "false" testconnectiononcheckout= "false"/>
Maxpoolsize properties, similar to Maxactive
MaxIdleTime property, maximum space connection reclaim time
Idleconnectiontestperiod Property Idle connection detection interval, per second
The following is a summary of the reference, transferred from http://www.cnblogs.com/HD/p/3627581.html
Description of the relevant parameters:? DataSource: DataSource to be connected (usually we are not defined in Server.xml) Defaultautocommit: The default value is true for transactions autocommit Defaultreadonly: For database read only, the default value is False driverclassname: the JDBC Driver Class used to connect to the database, maxactive: The maximum number of objects that can be fetched from the object pool, 0 means no limit, the default is 8 Maxidle: The maximum number of waiting connections, set 0 is no limit (the maximum number of objects in the object pool) Minidle: The minimum number of objects in the object pool maxwait: The maximum wait seconds, in MS, the time will drop error message, 1 is unlimited p Assword: The password URL used to log into the database: the URL of the connection database username: The account used to log in to the database validationquery: Verify that the connection is successful, and that the SQL SELECT directive returns at least one row removeabandoned: is self-interrupting, the default is False removeabandonedtimeout: After a few seconds self-interrupts, removeabandoned must be true logabandoned: whether the interrupt event is logged, the default is False minevictabl Eidletimemillis: Greater than 0, the connection idle time is judged, or 0, the idle connection is not verified; default 30 minutes Timebetweenevictionrunsmillis: The Expiration check thread run time interval, if it is less than or equal to 0, Does not start the check thread, default-1 Testonborrow: Whether to validate when an object is obtained, check if the object is valid, default to False Testonreturn: whether to validate when returning an object, check if the object is valid, default to False Testwhileidle: Are you validating when idle, checking that the object is valid, and default to False? When using the DBCP, if the default value is used, the connection to the database connection is actually invalid when it is disconnected from the connection pool for some reason and the connection is not validated. Therefore, in order to prevent the access to the database connection fails, it is best to ensure that: Username: Login Database validationquery:select COUNT (*) from DUAL Testonborrow, Testonreturn, Testwhileidle: Preferably set to true Minevictableidletimemillis: greater than 0, connection idle time is judged, or 0, idle connections are not verified Timebetweenevictionrunsmillis: Failure Check thread run time interval, if less than equals 0, check thread does not start? PS: When constructing Genericobjectpool [Basicdatasource also uses Genericobjectpool] in its CreateDataSource () method, an inline class evictor is generated, Implement the self-runnable interface. If Timebetweenevictionrunsmillis is greater than 0, every timebetweenevictionrunsmillis milliseconds Evictor calls the evict () method, Check if the object is idle for more than Minevictableidletimemillis milliseconds (_minevictableidletimemillis is less than or equal to 0 o'clock, default is 30 minutes), then destroy the object, or activate and validate the object. Then call the Ensureminidle method to check to make sure that the number of objects in the pool is not less than _minidle. When you call the Returnobject method to put the object back into the object pool, first check that the object is valid, and then call Poolableobjectfactory's Passivateobject method to make the object inactive. To check if the number of objects in the object pool is less than maxidle, then you can put this object back into the object pool, or destroy this object? The setting of the above features has been verified in the code, whether the specific performance can be implemented to verify the actual
Tomcat Database Connection Pool configuration