# Initialize Connection: Number of initial connections created at Connection pool startup initialsize=1# Minimum idle connection: the minimum number of connections allowed to remain idle in the connection pool, below which a new connection is created and if set to 0 does not create a minidle=1# maximum idle connection: The maximum number of connections allowed to remain idle in the connection pool, excess idle connections will be released, and if set to a negative number, no Limit maxidle=2# maximum active connections: The maximum active connections that the connection pool can allocate at the same time, if set to non-positive, means no limit maxactive=3# Do not test when lending a connection, otherwise it will affect performance testonborrow=false# indicates whether the connection is verified by the idle connection collector (if any). If the detection fails, the connection is removed from the pool. testwhileidle=true# Run idle connection collector every x seconds timebetweenevictionrunsmillis=30000# The missing link is removed when the checksum thread completes the checksum removeabandonedonmaintenance=true# query checksum Validationquery=select 1
-----------------------------
Self-detection of DBCP connection pool
-----------------------------
The default configuration of the DBCP connection pool, is not to test the connection in the pool, sometimes the connection has been broken, but the DBCP connection pool do not know, and thought the connection is good.
Application removing such a connection from the pool accessing the database must be an error. That's why so many people don't like dbcp.
Problem Example One:
MySQL8 hours problem, MySQL server default connection "Wait_timeout" is 8 hours, that is, a connection idle for more than 8 hours, MySQL will automatically disconnect the connection.
However, the DBCP connection pool does not know that the connection has been disconnected, and if the program happens to use the disconnected connection, the program will report an error.
Problem Example Two:
In the past, the Sybase database was used, and for some reason the database was restarted after it died, or after a network break.
After waiting for about 10 minutes, the connection in the DBCP connection pool is still not available (disconnected), Access data application has been error, and finally can only restart the Tomcat problem to solve.
Solution:
Scenario 1, timed to test the connection, the test failed to close the connection.
Scenario 2, control the idle time of the connection to n minutes, close the connection (and then create a new connection).
The above two scenarios can be solved by using either of two types of problems. If you use Scenario 2 only, suggest N <= for 5 minutes. The connection can be resumed up to 5 minutes after it has been disconnected.
You can also mix two scenarios and suggest N = 30 minutes.
Here is the DBCP connection pool, which uses the configuration configuration of the above two scenarios
Validationquery = "Select 1" verifies that the connection is available, using the SQL statement
Testwhileidle = "True" indicates whether the connection is verified by the idle connection collector, if any. If the detection fails, the connection is removed from the pool.
Testonborrow = "false" do not test when lending a connection, otherwise it will affect performance
-----------------------------
DBCP Connection Pool Configuration parameter considerations
-----------------------------
The Maxidle value should be configured close to the Maxactive value.
Because, when the number of connections exceeds the Maxidle value, the connection that has just been used (just idle) is immediately destroyed. Instead of I want the idle m seconds before destroying a buffering effect. This dbcp may be different from what you might have imagined.
If the maxidle should be different from maxactive, in a high-load system will lead to frequent creation, destruction of connections, the number of connections between Maxidle and maxactive fast and frequent fluctuations, this is not what I want.
The Maxidle value of a high-load system can be set to be the same as maxactive or set to 1 (1 for unlimited), allowing the number of connections to buffer slow fluctuations between minidle and Maxidle.
Timebetweenevictionrunsmillis Recommended Setting values
Initialsize= "5" will create 5 connections at the start of Tomcat, which is ideal.
But at the same time we also configured the minidle= "10", that is, to maintain a minimum of 10 connections, then there are only 5 connections, when and when to create a few 5 connections?
1, and other business pressure comes up, DBCP will create a new connection.
2, configure timebetweenevictionrunsmillis= "time", DBCP will enable independent worker thread timing check, make up less 5 connections. The same is true for destroying redundant connections.
------------------------------
Logic for Connection Destruction
------------------------------
The number of DBCP connections varies between 0-minidle-maxidle-maxactive. The logical description of the change is as follows:
When InitialSize is not configured by default (the default is 0) and the Timebetweenevictionrunsmillis parameter, the number of connections is 0 when you just start Tomcat. When an app has a concurrent Access database, DBCP creates a connection.
The current number of connections has not reached Minidle, but DBCP does not automatically create new connections that have reached the number of minidle (without a separate worker thread to check and create).
With the increase of application concurrent Access database, the number of connections also increased, but are not related to Minidle value, and soon Minidle was surpassed, Minidle value a little use.
Until the number of connections reaches the Maxidle value, the connection is only increased. Further development, the number of connections increased and more than Maxidle, the use of the connection (just idle) will be closed immediately, the total number of connections is stable maxidle but not more than Maxidle.
However, the active connection (the connection in use) may have an instantaneous amount of more than maxidle, but never more than maxactive.
At this point, if the application business pressure is small, access to the database is less concurrency, the number of connections will not be reduced (not a separate thread to check and destroy), will remain in the number of maxidle.
InitialSize is not configured by default (the default value is 0), but when you start Tomcat, the number of connections is 0 when you configure the timebetweenevictionrunsmillis= "30000" (30 seconds) parameter. Immediately when you apply a concurrent Access database, DBCP creates a connection.
Currently the number of connections has not reached Minidle, every 30 seconds DBCP worker thread checks whether the number of connections is less than minidle, if less than create a new connection until the Minidle quantity is reached.
As the application concurrently accesses the database, the number of connections increases until the Maxidle value is reached. During this period, each 30-second DBCP worker thread checks if the connection is idle for 30 minutes, if it is destroyed. But at this time is the peak of the business, there will not be up to 30 minutes of idle connection, working thread check is also a white check, but it is working. The number of connections here has been a growing trend.
When the number of connections increases more than Maxidle, the used connections (just idle) are immediately closed and the total number of connections is stable at maxidle. The trend of growth has ceased. However, the active connection (the connection in use) may have an instantaneous amount of more than maxidle, but never more than maxactive.
At this time, if the application business pressure is small, access to the database is less concurrency, every 30 seconds dbcp worker thread Check the connection (default 3) is idle for 30 minutes (this is the default value), if the connection is idle for 30 minutes, the connection is destroyed. At this point, the number of connections decreased, a downward trend, will move from Maxidle to Minidle. When the value is less than Minidle, then DBCP creates a new connection that has stabilized the number of Minidle and has been replaced by new and old.
When you configure Initialsize= "10", Tomcat creates 10 connections as soon as it starts. Other ibid.
Minidle is useful for working with Timebetweenevictionrunsmillis, and using minidle alone will not work.
This article is from the "9865854" blog, please be sure to keep this source http://9875854.blog.51cto.com/9865854/1902686
DBCP Connection Pool Introduction