Tomcat connection pool

Source: Internet
Author: User

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 ).

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.