Working principle of database connection pool and the generation of this technology, working principle of Database Connection
Why does this technology exist?
Database connection is a very precious and limited resource, especially on the network of multiple users. The management of databases directly affects the performance of the entire system.
1. Creating a database connection is a very time-consuming operation. If every user needs to create a database connection in the page application, the response time will be very long, which will affect the user experience.
2. The number of database connections is limited. If the management is poor and users often establish connections with the database but forget to release it, the database connection resources will be exhausted after a long running time, when there are new user operations, they will wait until the resources are released, which affects the system availability. Therefore, it is very important to manage database connection resources, especially web application systems.
Working principle of Database Connection Pool
The database connection pool is responsible for allocating, managing, and releasing database connections. It allows repeated use of only one existing database connection, rather than creating a new database connection, at the same time, it is also responsible for releasing database connections that have exceeded the maximum idle time to avoid omissions caused by the absence of database connections.
In j2ee, a certain number of pool connections will be created when the server is started, and a certain number of connections will be maintained, when you need to connect to a database, use a pool connection (idle pool connection) instead of creating a new database connection and mark it as busy, after you use the database connection, the current connection is released and marked as a space connection. If there is no idle connection during use, the server will create a new database connection according to the parameter configuration. Using this method will greatly increase the system response time and improve the running efficiency. On the other hand, to improve operation performance, database connections will release the database connections with the current idle time exceeding the maximum idle time, so as to avoid omissions due to the absence of database connections.