Druiddatasource configuration is compatible with DBCP, but the semantics of individual configurations are different.
|to configure||Default value||explain|
|name||The significance of configuring this property is that if there are multiple data sources, they can be distinguished by name when monitoring. If there is no configuration, a name will be generated in the format of “datasource -“+ System.identityHashCode (this). In addition, configuring this property does not work at least in version 1.0.5. Forcing name setting will cause errors. Details – click here.|
|url||The URL to connect to the database is different for different databases. For example: MySQL: jdbc:mysql ://10.20.153.104:3306/druid2 oracle : jdbc:oracle:thin:@10.20.149.85 :1521:ocnauto|
|username||User name to connect to the database|
|password||Password to connect to the database. If you don’t want the password written directly in the configuration file, you can use configfilter. See here for details|
|driverClassName||Automatic identification based on URL||This item can be configured or not. If Druid is not configured, the dbtype will be automatically identified according to the URL, and then the corresponding driverclassname will be selected|
|initialSize||0||The number of physical connections established during initialization. Initialization occurs when the display calls the init method, or the first getconnection
Configure init method when initializing bean
|maxActive||8||Maximum number of connection pools
(maximum number of active sessions supported in connection pool)
|maxIdle||8||It is no longer used, and the configuration has no effect|
|minIdle||Minimum number of connection pools
(when reclaiming idle connections, at least minidle connections will be guaranteed.)
|maxWait||The maximum waiting time for getting a connection, in milliseconds. After maxwait is configured, fair lock is enabled by default, and concurrency efficiency will decrease. If necessary, you can use unfair lock by configuring the useunfairlock attribute to true.
(when the program requests a connection from the connection pool, if the value of maxwait is exceeded, the request is considered to have failed, that is, there is no available connection in the connection pool. The unit is milliseconds. When – 1 is set, it means infinite waiting.)
|poolPreparedStatements||false||Whether to cache the Preparedstatement, or pscache. Pscache greatly improves the performance of databases supporting cursors, such as Oracle. It is recommended to close under mysql.
Caching SQL initiated by two methods:
public PreparedStatement prepareStatement(String sql)
public PreparedStatement prepareStatement(String sql,int resultSetType, int resultSetConcurrency)
|maxPoolPreparedStatementPerConnectionSize||-1||To enable pscache, you must configure a value greater than 0. When the value is greater than 0, poolpreparedstatements will be automatically triggered to true. In Druid, there is no problem that the pscache in Oracle takes up too much memory. You can configure this value larger, for example, 100
How many SQL queries can be cached at most per connection
|validationQuery||The SQL used to check whether the connection is valid requires a query statement, and select ‘x’ is commonly used. If validationquery is null, testonborrow, testonreturn, and testwhileidle will not work.
Check whether the connection in the pool is still available. Druid will connect to the database to execute the SQL. If it returns normally, it means that the connection is available. Otherwise, it means that the connection is not available
|validationQueryTimeout||Unit: seconds, the timeout to check whether the connection is valid. The underlying layer calls the void setquerytimeout (int seconds) method of JDBC statement object|
|testOnBorrow||false||When applying for a connection, the validationquery is executed to check whether the connection is valid. This configuration will reduce the performance.|
|testOnReturn||false||When the connection is returned, the validationquery is executed to check whether the connection is valid. This configuration will reduce the performance.|
|testWhileIdle||true||It is recommended that the configuration be true, which will not affect the performance and ensure the security. Check when applying for a connection. If the idle time is greater than timebetweenevecicationrunsmillis, execute validationquery to check whether the connection is valid.|
|keepAlive||false （1.0.28）||If the number of minidles in the connection pool is less than, and the idle time exceeds minevictableidle timemillis, the keepalive operation will be performed.
If the program has no close connection and the idle time is longer than minevictableidle timemillis, the SQL specified by validationquery will be executed to ensure that the connection pool of the program will not be killed, and the scope will not exceed the number of connections specified by minidle.
|timeBetweenEvictionRunsMillis||1 minute (1.0.14)||There are two meanings: 1) the destroy thread will detect the connection interval, and close the physical connection if the connection idle time is greater than or equal to min evictable idle time millis. 2) For the judgment basis of testwhileidle, see the description of testwhileidle attribute for details
Check the frequency of idle connections, in milliseconds. Non positive integer means no check
|numTestsPerEvictionRun||30 minutes (1.0.14)||No longer used. A druiddatasource only supports one evicationrun|
|minEvictableIdleTimeMillis||The minimum time for a connection to remain idle without being evicted, in milliseconds
When the idle time of a connection in the pool reaches n MS, the connection pool will recycle the connection when checking the idle connection next time, which should be less than the firewall timeout setting net.netfilter.nf_ conntrack_ tcp_ timeout_ Setting of established
|connectionInitSqls||SQL executed during physical connection initialization|
|exceptionSorter||Automatic identification based on dbtype||When the database throws some unrecoverable exceptions, discard the connection|
|filters||The attribute type is string, and the extension is configured by alias. The common plug-ins are: for monitoring and statistics filter:stat It’s for the log filter:log4j Or slf4j defense SQL injection filter:wall|
|proxyFilters||The type is list< com.alibaba.druid . filter.Filter >If filters and proxyfilters are configured at the same time, it is a combination relationship, not a replacement relationship|
|asyncInit||The newly added configuration in 1.1.4, if there is a large number of initialsize, will speed up the application startup time|