druid parameter configuration in detail

druid parameter configuration in detail

1 initiates the connection

Druid configuration file database connection, the reader datasource bean that have the init =-Method "the init" . Configuration will not execute the initialization operation when initiating a connection pool. Example:

<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
.......
  </bean>

2 Parameter Configuration and Description

Instructions for configuring the various parameters of the application-context.xml dataSource configuration by spring configuration files.

<the bean ID = "the dataSource" class = "com.alibaba.druid.pool.DruidDataSource" = the init-Method "the init" the destroy-Method = "Close"> 
      <-! "connected" basic properties url, user, password -> 
      <-! JDBC URL: 
      <Property name = "URL" value = "jdbc_url" /> 
      <Property name = "username" value = "$ {jdbc_user}" /> 
      <Property name = "password" value = "$ {jdbc_password}" /> 

      <-! start druid, the synchronization establishing connections N -> 
      <Property name = "initialSize" value = "100" /> 
      <-! up to N active connection pool connection -> 
      <Property name = "for maxActive" value = "1000" /> 

      <!- program requests connection to the connection pool maximum latency of this operation, after this time, that this fails, i.e. the connection pool is not available connections, will exit request operation, in milliseconds, to wait for infinite -1 - -> 
      <Property name = "maxWait" value = "60000" /> 

      <-! idle connection mechanism connection pool recovery, recycling and comprising two parts, checking ->

      <- Check range:! N grow in milliseconds, the connection pool will be considered recovered when the connection is idle. This parameter determines the scope of the inspection recovery mechanisms -> 
      <Property name = "minEvictableIdleTimeMillis" value = 300000 /> 

      <- Check Frequency:! Frequency Check idle connection, in milliseconds, non-integer timing is not checked. -> 
      <Property name = "timeBetweenEvictionRunsMillis" value = -1 /> 

      <- 1 recovered restrictions:! Idle connection recovery, will ensure that at least the N idle connections -> 
      <Property name = "minIdle" value = "20" /> 

      <! - open connectivity mandatory recycling, mandatory recycling program in connection required to get within N seconds after the connection must close the connection, otherwise the druid will be forced to suspend the connection, if any transactions are running regardless of whether the connection . -> 
      <Property name = "removeAbandoned" value = "to true" /> 

      <-! When the program to get a connection must Close within N seconds, otherwise the connection pool will kill it, to be considered a reasonable values, without the business running endless -> 
      <Property name = "removeAbandonedTimeout" value = "180 [" />


      <-! All basic relational database will be mandatory long idle connection is disconnected. But this connection remains in the connection pool. These program gets broken connection will be given -> 
      <! - The following four parameters are used to check the connection is valid, if available -> 
      <! - idle open connections validity detector -> 
      <Property name = "testWhileIdle" value = "to true" /> 
      <-! confirms connectivity of the SQL -> 
      <Property name = "validationQuery" value = "the SELECT 'X'" /> 

      <-! following two affect performance parameters, not recommended -> 
      <! - acquiring program detects when connection pool -> 
      <property name = "testOnBorrow" value = "to false" /> 
      program return connection - <! detecting the connection is still valid -> 
      <Property name = "testOnReturn" value = "to false" /> 

      <-! PSCache opened, and specifies the size of each connection PSCache -> 
      <
      <! - Configure monitoring statistics blocked filters, the attribute type is a string, the configuration extension by way of an alias, common plug-ins are: monitoring statistics with filter: stat; log with filter: log4j; defense SQL injection filter : Wall -> 
      <property name = "Filters" value = "STAT, Wall, SLF4J" /> 
      ! <- mergeSql function to open by connectProperties attribute; SQL record slow -> 
      <property name = "ConnectionProperties" value = "= druid.stat.mergeSql to true; druid.stat.slowSqlMillis = 5000" /> 
</ the bean>

When using Ali SLB, it recommended timeBetweenEvictionRunsMillis set to two seconds or negative (closed check mechanism). Otherwise, the connection process will be reported:

Could not open JDBC Connection for transaction; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicaiotnsException: Communications link failure

Author: halberd.lee

Created: 2019-08-05 Mon 18:35

Validate

Guess you like

Origin www.cnblogs.com/halberd-lee/p/11304790.html