1. Analysis
See the title DBCP the first thought is certainly the database connection pool which aspect has the question, then does not worry to solve, does not have a brain to drill into the logic code, then enables the debugging to start step by step
The analysis. The first thing we need to do is think about how the database connection pool is implemented in the project, so whether you're early or late, you'll think of the configuration files and code associated with the database connection pool. So
The question is, is there a problem with the configuration file configuration (mining technology which is strong?). )?
So let's analyze the properties of each connection pool configuration first:
#回收被遗弃的 (typically forget to release) the database is connected to the connection pool.
database.removeabandoned =false
# The database connection is too long to be considered abandoned and the connection pool is reclaimed.
Database.removeabandonedtimeout = 30
# Log The discarded database connection's recycle.
Database.logabandoned = False
#连接池的最大数据库连接数, set to 0 to indicate no limit.
Database.maxactive = 200
#数据库连接的最大空闲连接数. After this number of idle connections is exceeded, the database connection is marked as unavailable and then released. Set to 0 to indicate no limit.
Database.maxidle=40
#最大建立连接等待时间. If this time is exceeded, the exception will be received. Set to-1 means no limit
database.maxwait=10000
#取得, return object, and whether to validate when idle, check whether the object is valid, false by default, and no validation
Database.testonborrow=true
Database.testwhileidle=true
Database.testonreturn=true
Database.validationquery=select 1 from dual
Description
1. #回收被遗弃的 (typically forgot to release) The database is connected to the connection pool.
database.removeabandoned =false
If this value is true, it is usually used for debugging purposes and should be changed to false,2 after the official release. # Log The discarded database connection's recycle.
Database.logabandoned = False
This, if set to True, causes the following error:
DBCP object created date by the following code is never closed:
Java.lang.Exception
3. #连接池的最大数据库连接数, set to 0 means no limit.
Database.maxactive = 200
#数据库连接的最大空闲时间. When this idle time is exceeded, the database connection is marked as unavailable and then released. Set to 0 to indicate no limit.
Database.maxidle=40
It is possible to appear: Cannot get a connection, pool error Timeout waiting for idle object such errors
(Reprint online information)
2. In-depth
Careless exposure to the solution, then what exactly is it?
The reason is: database.removeabandoned = True
When set to True, using this configuration will use Abandonedobjectpool, as mentioned above, and this configuration is only recommended for use in the development phase
Because, Abandonedobjectpool can help you to find the use of long-connected code, such as log information, indicating the time getcustomeronline occupied the connection
The Removeabandonedtimeout set time is exceeded, so setting database.removeabandoned = False is OK,
Abandonedobjectpool is only used in development, the subsequent versions are removed, and now the API is deprecated (disapproved), so use this
The function of the time to pay attention.
DBCP object created date by the following code is never closed: