Database Connection Pool

Source: Internet
Author: User

Database Connection Pool

Database connection Pooling Overview: Database Connectivity is a critical, limited and expensive resource that is particularly evident in multi-user Web applications. The management of database connections can significantly affect the scalability and robustness of the entire application, affecting the performance metrics of the program.  The database connection pool is proposed for this problem. The database connection pool is responsible for allocating, managing, and freeing the database connection, which allows the application to reuse an existing database connection without having to re-establish a database connection that frees up idle time beyond the maximum idle time to avoid missing the database connection caused by not releasing the database connection.  This technique can significantly improve the performance of database operations. When the database connection pool is initialized, a certain number of database connections are created into the connection pool, which is set by the minimum number of database connections. Regardless of whether or not these database connections are used, the connection pool will always ensure that there are at least as many connections. The maximum number of database connections for the connection pool limits the maximum number of connections that the connection pool can hold, and when the application requests more connections to the connection pool than the maximum number of connections, the requests are added to the wait queue. The minimum number of connections to the database connection pool and the maximum number of connections are set to take into account the following factors: 1 The minimum number of connections is the database connection that the connection pool maintains, so a large number of database connection resources will be wasted if the application does not use the database connection very much; 2  The maximum number of connections is the maximum number of connections that can be requested by the connection pool, and if the database connection request exceeds this number, subsequent database connection requests will be added to the wait queue, which can affect subsequent database operations. 3 If the minimum number of connections to the maximum number of connections is too large, then the first connection request will be profitable, then the connection request exceeding the minimum number of connections is equivalent to establishing a new database connection. However, these database connections that are larger than the minimum number of connections are not released immediately after use, and will be released in the connection pool pending reuse or idle timeout.

Tomcat6.0 Connection Pool Configuration
1. Configure the Context.xml files under Tomcat under Conf to add a connection pool configuration between:
<resource name= "Jdbc/sample"
Auth= "Container"
Type= "Javax.sql.DataSource"
Driverclassname= "Com.microsoft.sqlserver.jdbc.SqlserverDriver"
Url= "Jdbc:sqlserver://localhost:8080;databasename=test"
Username= "SA"
password= "SA"
Maxactive= "100"
Maxidle= "30"
maxwait= "10000"/>

2. Configure the Web.xml in your application to add between:
<resource-ref>
<description>db connection</description>
<res-ref-name>jdbc/sample</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

3. Put the third party drive connected to the database under Common/lib.
4. Test program (key code)
Context ctx = new InitialContext ();
DataSource ds = (DataSource) ctx.lookup ("Jdbc/sample");
Connection con = ds.getconnection ();
The following are the same as the JDBC operation code ...

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.