Atat6.x configure and use the connection pool

Source: Internet
Author: User

In this tutorial, Tomcat 5.x is used. You can directly configure datasource on the Tomcat page. My website is Tomcat 6.x. After logging on to Tomcat, you will find that there is no Tomcat administration Web application item.

The original core installation version after Tomcat 5.5 is no longer integrated with the Tomcat administration web application, and requires independent download and installation. The administration Web Application of Tomcat 6.0.13 is only contained in the source package and does not have an independent installation package. The following describes how to deploy the Tomcat administration Web application to Tomcat.

Connection Pool

When the amount of data operated is small, it takes a short time to operate the database, but it takes a long time to close and open the database connection. The function of the connection pool is to establish a database connection in advance, when the thread is used, it can be called. Close the connection and return it to the connection pool.

The following definitions need to be explained: Maximum number of connections, minimum number of connections, getting links, and closing connections:

  • The minimum number of connections refers to the number of database connections established during connection pool initialization, which is the minimum limit for the connection pool to maintain connections.
  • When connections in the connection pool are insufficient, the connection pool can continue to create new connections. The maximum number of connections refers to the upper limit of connections in the connection pool. When the upper limit is reached, the connections are still insufficient, the thread can only get the connection after other connections are released.
  • After the connection pool is used, the connection of the thread is no longer obtained from the database, but the existing connection is obtained from the connection pool.
  • Close the connection. When the thread uses conn. Close (), it does not actually destroy the connection, but returns the connection to the connection pool.

Deployment

  • Download the admin applicationof Tomcat 5.5.23, decompress apache-atat-5.5.23-admin.zip, and copy the conf and server folders to the Tomcat 6.0.13 installation directory.
  • Load Apache commons modeler, logging component, unzip and copy the commons-modeler-XXX.jar and commons-logging-XXX.jar to the lib directory under Tomcat 6.0.13 installation directory.
  • Start Tomcat and enter http: // 127.0.0.1: 8080/admin in the browser. If you can see the logon interface of Tomcat web server administration tool, the installation is successful. If not, you can view Tomcat 6.0.13 installation directory in the logs directory of log files such as (Admin. xxxx-xx-xx.log), to see what is wrong. The installation successful page is as follows:


Configuration

The installation is complete and the Tomcat user has not been added. Configure the Tomcat user as follows.

Add a user under the tomcat/CONF/tomcat-user.xml:

<user username="admin" password="admin" roles="manager,admin" />

Browse http: // 127.0.0.1: 8080/admin, log on to resources --- CES --- create new data source, and create a new connection pool. The preceding steps are only used to visualize datasource operations. If admin is not installed
Application, manually modify the configuration file:

<Resource      name="jdbc/drp"      type="javax.sql.DataSource"      password="drp1"      driverClassName="oracle.jdbc.driver.OracleDriver"      maxIdle="2"      maxWait="5000"      username="drp1"      url="jdbc:oracle:thin:@localhost:1521:DrpDB"      maxActive="4"/>

Use

Use JNDI to search for and use it:

/*** Get connection * @ return */public static connection getconnection () {connection conn = NULL; preparedstatement pstmt = NULL; resultset rs = NULL; try {// new DBCP .... context CTX = new initialcontext (); // use JNDI to find datasource DS = (datasource) CTX. lookup ("Java: COMP/ENV/jdbc/DRP"); Conn = Ds. getconnection ();} catch (exception e) {e. printstacktrace (); throw new applicationexception ("database connection error, please contact the Administrator");} return conn ;}

Summary

How can I set the maximum number of connections and the minimum number of connections to achieve the optimal number of connections? This still needs to be set based on the specific situation. The connection pool is only a way to optimize the database connection. Other aspects, such as programming control and optimization operations, still need to be put into practice to get a suitable solution.

Appendix:

1. commons-modeler:
Http://apache.mirror.phpchina.com/commons/modeler/binaries/commons-modeler-2.0.1.zip
2. commons-logging:
Http://apache.mirror.phpchina.com/commons/logging/binaries/commons-logging-1.1.zip

3. Admin application:
Http://apache.mirror.phpchina.com/tomcat/tomcat-5/v5.5.23/bin/apache-tomcat-5.5.23-admin.zip

For more DRP blogs, visit DRP project summary.

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.