Tomcat connection pool, at least two jar packages need to be used
1, JDBC package, I use MySQL here, the connection package is mysql-connector-java-5.0.6-bin.jar, this can be downloaded from the MySQL website
Tomcat (5.5) placed \ common \ Lib, Tomcat 6 placed under Tomcat 6.0 \ Lib
2. DBCP package, tomcat5.5 built-in naming-factory-dbcp.jar
tomcat6 built-in tomcat-dbcp.jar
In fact, the configuration of the connection pool is through the JNDI (Java Naming and Directory Interface Java Naming Directory Interface) the connection class as the cache object. To reduce frequency connections and close data connections.
The following is a key step: Modify the context in the conf directory of Tomcat. XML file, add
auth = "Container"
type = "javax. SQL. datasource "
maxactive =" 100 "maxidle =" 20 "maxwait =" 500 "
username =" root "Password =" "
driverclassname =" com. mySQL. JDBC. driver "
url =" JDBC: mysql: // localhost: 3306/mydb "/>
:
name: data source name. The lookup name must be the same as the name.
mydb: MySQL database name
maxid Le: idle connection, that is, start the connection pool and the number of initialized connections
maxactive: active connection, that is, the maximum number of connections in the connection pool
maxwait: maximum number of pending connections
maxidle and macactive are key factors.
the main operations of the database connection pool are as follows:
(1) Create a database connection pool object (server startup ).
(2) create an initial number of database connections (idle connections) based on the specified parameters ).
(3) Obtain a connection from the connection pool for a database access request. If there is no idle connection in the database connection pool object and the number of connections does not reach the maximum (that is, the maximum number of active connections), create a new database connection.
(4) access the database.
(5) Close the database and release all database connections (close the database connection at this time, rather than actually close it, but put it into the idle queue. If the actual number of idle connections is greater than the initial number of idle connections, the connection is released ).
(6) release the database connection pool object (during server stop and maintenance, release the database connection pool object and release all connections ).