Summary of DBCP applications (2)
In this article, I 'd like to share with you how DBCP gets the connection.
First, my configuration is as follows:
Initialsize = 1 minidle = 1 maxidle = 2 maxactive = 20 # Whether the idle link verifies testwhileidle = true # validationquery = select 1 # When the connection is exhausted, how long will it take to recover lost connections maxwait = 1000 # Whether to automatically recycle the timeout connection removeabandoned = true # The timeout wait time is measured in milliseconds removeabandonedtimeout = 300 # Whether to print the connection when the timeout connection is automatically recycled logabandoned = true
Next let's take a look at the connection information of the database:
There are only two initial connections. When I query these connections, they can be used directly as long as they are idle. However, when I perform write operations, somehow, a new connection will be generated. To find the reason, I plan to start with the getconnection method to find out the actual problem. First, I found the sequence diagram on the official website:
The borrowobject method has the following logic:
If (config! = NULL & config. getremoveabandoned () & (getnumidle () <2) & (getnumactive ()> getmaxactive ()-3) {removeabandoned ();}
After the method is called, the number of connections remains unchanged.