JDBC3.0 Research Report (excerpt)

Source: Internet
Author: User
Tags connection pooling

Fundamentals of database connection pooling

Traditional database connection way (refers to connect through DriverManager and basic realization DataSource), a database connection object all corresponds to one physical database connection, the database connection establishment and the shutdown to the system is consumes the system resources the operation, This resource-consuming action has a particularly significant impact on the performance of the system in a multi-tiered application environment.

The performance of the system is clearly mentioned through connection pooling (connection pooling) technology in multi-tier applications, and connection pooling means that when an application needs to call a database connection, Database-related interfaces to re-create a database connection by returning a database connection by reusing it. In this way, applications can reduce database connection operations, especially in multi-tier environments where multiple clients can meet system requirements by sharing a small number of physical database connections. By connecting pool technology, Java applications can not only improve system performance but also improve the scalability of the system.

The database connection pool is run in the background and the application's encoding has no effect. The condition in this case is that the application must replace the original way of obtaining a database connection through the DriverManager class by DataSource the object (an instance of the Javax.sql.DataSource interface). A class that implements the Javax.sql.DataSource interface can support or not support a database connection pool, but the code that obtains a database connection is basically the same.

The code is as follows:

A DataSource object is usually registered on the Jndi Naming service, and the application can obtain the DataSource object registered on the Jndi service in a standard way.

Context ctx = new InitialContext ();

DataSource ds = (DataSource) ctx.lookup ("Jdbc/openbase");

If the current datasource does not support a database connection pool, the application obtains a connection object corresponding to the physical database connection. If the current DataSource object supports database connection pooling, the application automatically obtains a reused database connection without creating a new database connection. There is no difference between a reused database connection and a newly established connection database connection. The application can access the data by using a reusable connection to the database, and then explicitly call Close () to shut down the database connection after completing the operation.

Connection con = ds.getconnection ("User", "Pwd");

The operation of the related database;

Con.close ();

When the data connection is turned off, the database connection currently in use will not be physically shut down, but put back into the database connection pool for reuse.

Database connection pool framework in JDBC3.0 specification

The JDBC3.0 specification provides a framework for supporting the database connection pool, which only specifies how to support the implementation of the connection pool, while the implementation of the JDBC 3.0 specification for the connection pool does not provide relevant provisions. This framework enables developers of different roles to work together to implement database connection pooling.

Through the JDBC3.0 specification can know that the implementation of specific database connection pool can be divided into JDBC driver level and application server level. Any relevant work in the JDBC driver-level implementation is specifically implemented by the JDBC Drvier developer of a particular database vendor, that is, JDBC driver needs to provide support for the database connection pool, as well as a specific implementation of the database connection pool. In the implementation of the database connection pool at the application server level, the JDBC driver developer and application Server developer of a particular database manufacturer together implement the database connection pool (but now most application The mechanisms and specifications for connection pooling implemented by the server manufacturer refer to differences in that the JDBC driver for a particular database vendor provides support for the database connection pool and specific application server vendors provide a concrete implementation of the database connection pool.

The JDBC3.0 specification provides the following classes and interfaces to support the implementation of the database connection pool.

Javax.sql.ConnectionEvent

Javax.sql.ConnectionPoolDataSource

Javax.sql.PooledConnection

Javax.sql.ConnectionEventListener

In addition to Javax.sql.ConnectionEvent is the class, the other is the interface.

Diagram of the JDBC3.0 connection pool framework

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.