Dbcp2 data source configuration details, dbcp2 details
DBCP2 detailed configuration table common link configuration
Parameters |
Description |
Username |
User name passed to the JDBC driver for connection Establishment |
Password |
The password passed to the JDBC driver for establishing the connection |
Url |
URL passed to the JDBC driver for connection Establishment |
DriverClassName |
Complete and valid java class name of the JDBC driver used |
ConnectionProperties |
The connection parameter sent to the JDBC driver when a new connection is established. The format must be [propertyName = property;]. Note: The user/password parameter will be passed explicitly, so it is not required here. |
Data source connection quantity Configuration
Parameters |
Default Value |
Description |
InitialSize |
0 |
Initial connection: the number of initial connections created when the connection pool is started. supported after version 1.2 |
MaxActive |
8 |
Maximum number of active connections: the maximum number of active connections that can be allocated by the connection pool at the same time. If it is set to a non-positive number, it indicates no limit. |
MaxIdle |
8 |
Maximum number of idle connections: the maximum number of connections allowed to remain idle in the connection pool. If the number of idle connections exceeds the limit, the connections are released. |
MinIdle |
0 |
Minimum idle connection: the minimum number of connections that are allowed to remain idle in the connection pool. If the number is lower than this limit, a new connection is created. If the value is set to 0, no connection is created. |
MaxWait |
Unlimited |
Maximum wait time: when no connection is available, the maximum wait time (in milliseconds) for the connection pool to wait for the connection to be returned. If it is set to-1, an exception is thrown. |
Transaction attribute Configuration
Parameters |
Default Value |
Description |
DefaultAutoCommit |
True |
Default auto-commit status of the connection created in the connection pool |
DefaultReadOnly |
Driver default |
The default read-only status of the connection created by the connection pool. If no value is set, the setReadOnly method will not be called. (Some drivers do not support read-only mode, such as Informix) |
DefaultTransactionIsolation |
Driver default |
The default TransactionIsolation status of the connection created by the connection pool. One of the following lists: (refer to javadoc) NONE, READ_COMMITTED, READ_UNCOMMITTED, REPEATABLE_READ, and SERIALIZABLE |
DefaultCatalog |
|
Default catalog of the connection created in the connection pool |
Health Check of data source connection
Parameters |
Default Value |
Description |
ValidationQuery |
|
SQL query is used to verify the connection obtained from the connection pool. If this parameter is specified before the connection is returned to the caller, the query must be an SQL SELECT statement and at least one row of records must be returned. |
TestOnBorrow |
True |
Check whether the connection is retrieved from the pool. If the test fails, remove the connection from the pool and try to retrieve the other one. Note: If this parameter is set to true, the validationQuery parameter must be set to a non-null string. |
TestOnReturn |
False |
Indicates whether to perform a test before returning the data to the pool. Note: If this parameter is set to true, the validationQuery parameter must be set to a non-null string. |
TestWhileIdle |
False |
Indicates whether the connection is verified by the idle connection recycler (if any). If the detection fails, the connection will be removed from the pool. Note: If this parameter is set to true, the validationQuery parameter must be set to a non-null string. |
TimeBetweenEvictionRunsMillis |
-1 |
The time value of sleep during idle connection to the recycler thread running, in milliseconds. If it is set to a non-positive value, the idle connection to the recycler thread is not run. |
NumTestsPerEvictionRun |
3 |
Number of connections checked during each idle connection to the recycler thread (if any) |
MinEvictableIdleTimeMillis |
10006030 |
Minimum Time for the connection to be idle in the pool and not to be idle in milliseconds (if any) |
Cache statement
Parameters |
Default Value |
Description |
PoolPreparedStatements |
False |
Enable the prepared statement pool function of the pool. |
MaxOpenPreparedStatements |
Unlimited |
The maximum number of statements that can be allocated at the same time by the statement pool. If it is set to 0, it indicates no limit. |
Connection leakage recovery
Parameters |
Default Value |
Description |
RemoveAbandoned |
False |
Mark whether to delete the leaked connection if they exceed the removeAbandonedTimout limit. if this parameter is set to true, the connection is considered leaked and can be deleted. If the idle time exceeds removeAbandonedTimeout. if it is set to true, it can be used to fix the database connection for a program with no closed connection. |
RemoveAbandonedTimeout |
300 |
Timeout value that the leaked connection can be deleted, in seconds |
LogAbandoned |
False |
Indicates whether to print the stack trace log of the program when the Statement or connection is leaked. The leaked Statements and connection logs are added to each connection to open or generate a new Statement because stack trace needs to be generated. |
Note:
- The Java database connection has an "eight-hour problem", so destroy-method = "close" must be added. The "eight-hour problem" means that the database is automatically closed when a connection is idle for eight hours, but the data source is unknown.
- In highly concurrent scenarios, you can set testOnBorrow to false and testWhileIdle to true. In this way, empty links in the background are detected regularly and useless connections are cleared, it does not check whether there is an empty link for 8 hours every time.
Reference: http://blog.csdn.net/initphp/article/details/8255793
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.