The database connection pool is responsible for allocating, managing, and releasing database connections. During database connection pool initialization, a certain number of database connections are created and placed in the connection pool, the number of connections to these databases is set by the minimum number of connections to the database. Whether or not these database connections are used, the connection pool will always have at least so many connections. The maximum number of database connections in the connection pool limits the maximum number of connections that the connection pool can occupy. When the number of connections requested by the application to the connection pool exceeds the maximum number of connections, these requests will be added to the waiting queue. The following factors must be taken into account when setting the minimum number of connections and maximum number of connections in the database connection pool:
1) The minimum number of connections is the database connection that has been maintained by the connection pool. Therefore, if the application uses a small amount of database connections, a large amount of database connection resources will be wasted;
2) the maximum number of connections is the maximum number of connections that can be applied by the connection pool. If the number of database connection requests exceeds this limit, the subsequent database connection requests will be added to the waiting queue, which will affect subsequent database operations.
Java provides many container classes for us to easily build connection pools, such as vector and stack.
2. What is the working mechanism of the data connection pool?
When the J2EE server is started, a certain number of pool connections will be established, and a certain number of pool connections will be maintained. When the client program needs to connect, the pool driver returns an unused pool connection and marks it as "busy ". If no idle connection exists, the pool driver creates a certain number of connections. The number of new connections is determined by the configuration parameters. After the pool connection call is completed, the pool driver records the connection table as "idle". Other calls can use this connection.