Database Connection Pool, database connection pool java

Source: Internet
Author: User

Database Connection Pool, database connection pool java

I. Why should I use the database connection pool?

Database Connection resources are very expensive, especially when accessing the database through the network. A simple physical connection causes low performance.

Therefore, the concept of database connection pool is introduced, and resources are reused as much as possible, greatly saving the memory. Improves program performance.

You can also manage the database connection pool in a more personalized manner.

2. database connection pool?

The basic idea is "buffer pool ". It is equivalent to a bridge between applications and databases. At the beginning, we obtained the connection directly from the database,

Now we get the connection from the buffer pool. This "buffer pool" can also be controlled.

Iii. How does the database connection pool work?

The working principle of the Connection Pool consists of three parts: the establishment of the connection pool, the use and management of connections in the connection pool, and the closure of the connection pool.

1. Create a connection pool. Generally, during system initialization, the connection pool is established according to the system configuration and several connection objects are created in the pool so that they can be obtained from the connection pool when used.

The connections in the connection pool cannot be created or closed at will, which avoids system overhead caused by the arbitrary establishment and closure of connections.

2. Manage the connection pool. The connection pool management policy is the core of the connection pool mechanism. The allocation and release of connections in the connection pool have a great impact on the system performance.

Its management policy is:

When a customer requests a database connection, first check whether there is any idle connection in the connection pool. If there is a idle connection, the connection is allocated to the customer;

If there is no idle connection, check whether the number of connections currently opened has reached the maximum number of connections. If not, create a new connection to the requesting customer;

If the maximum wait time is reached, an exception is thrown to the customer.

When a customer releases a database connection, the customer first determines whether the reference times of the connection have exceeded the specified value. If so, the customer deletes the connection from the connection pool. Otherwise, the database is retained as another customer service.

This policy ensures effective reuse of database connections and avoids system resource overhead caused by frequent connection establishment and release.

3. Close the connection pool. When the application exits, close all connections in the connection pool and release resources related to the connection pool. This process is the opposite of creating a connection pool.

Iv. Common Database Connection pools

C3P0

DBCP

5. Use graphs to speak

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.