Druid connection pool simple entry configuration

Occasional opportunities to explain the Druid connection pool, a rising star, but the evaluation is good, and because it is used by Ali Taobao, it is still quite optimistic.

 

Druid integrates connection pools and monitoring into one to comprehend the needs of the current project. The project is a ssh structure, and C3p0 was used before. Now it is very simple to change a connection pool. First, spring configures the DataSource, and the configuration is as follows:

<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">   
    <!-- Basic attributes url, user, password -->  
    <property name="url" value="${jdbc_url}" />  
    <property name="username" value="${jdbc_user}" />  
    <property name="password" value="${jdbc_password}" />  
        
    <!-- Configure initialization size, minimum, maximum -->  
    <property name="initialSize" value="1" />  
    <property name="minIdle" value="1" />   
    <property name="maxActive" value="20" />  
   
    <!-- Configure the time for getting a connection to wait for timeout-->  
    <property name="maxWait" value="60000" />  
   
    <!-- How long is the configuration interval before detection is performed to detect idle connections that need to be closed, in milliseconds-->  
    <property name="timeBetweenEvictionRunsMillis" value="60000" />  
   
    <!-- Configure the minimum lifetime of a connection in the pool, in milliseconds-->  
    <property name="minEvictableIdleTimeMillis" value="300000" />  
    
    <property name="validationQuery" value="SELECT 'x'" />  
    <property name="testWhileIdle" value="true" />  
    <property name="testOnBorrow" value="false" />  
    <property name="testOnReturn" value="false" />  
   
    <!-- Open PSCache and specify the size of PSCache on each connection-->  
    <property name="poolPreparedStatements" value="true" />  
    <property name="maxPoolPreparedStatementPerConnectionSize" value="20" />  
   
    <!-- Configure the filters for monitoring statistics interception, after removing it, the monitoring interface sql cannot be counted -->  
    <property name="filters" value="stat" />   
</bean>

 At present, such a configuration can use the connection pool, be careful not to forget the jar file, download address: http://code.alibabatech.com/mvn/releases/com/alibaba/druid/

 

Then there is the monitoring configuration:

web.xml

 

<filter>  
        <filter-name>DruidWebStatFilter</filter-name>  
        <filter-class>com.alibaba.druid.support.http.WebStatFilter</filter-class>  
        <init-param>  
            <param-name>exclusions</param-name>  
            <param-value>*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*</param-value>  
        </init-param>  
      </filter>  
      <filter-mapping>  
        <filter-name>DruidWebStatFilter</filter-name>  
        <url-pattern>/*</url-pattern>  
      </filter-mapping>

 filter can monitor webURl access

<servlet>  
        <servlet-name>DruidStatView</servlet-name>  
        <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class>  
</servlet>  
<servlet-mapping>  
        <servlet-name>DruidStatView</servlet-name>  
        <url-pattern>/druid/*</url-pattern>  
</servlet-mapping>

 

This configuration can access the monitoring interface

 

After configuration, visit http://ip:port/projectName/druid/index.html

After the above configuration, we have been able to use and monitor the connection pool. This is just a simple introduction. If you want to learn more in detail, you have to communicate more on the forum.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327038115&siteId=291194637