Occasional opportunity to explain Druid connection pool, Up-and-comer, but the evaluation is good, in addition, because it is Ali Bao used so still pretty optimistic.
Druid Set Connection pool, monitor the integration of the current project needs, the project is the SSH structure, before the use of C3P0, now a connection pool is also very simple, first spring configuration DataSource, configured as follows:
<bean id= "DataSource" class= "Com.alibaba.druid.pool.DruidDataSource" init-method= "Init" destroy-method= "Close" > <!--Basic property URL, user, password--> <property name= "url" value= "${jdbc_url}"/> <property nam E= "username" value= "${jdbc_user}"/> <property name= "password" value= "${jdbc_password}"/> <!--
Configure initialization size, MIN, max--> <property name= "InitialSize" value= "1"/> <property name= "Minidle" value= "1"/> <property name= "maxactive" value= "/> <!--configuration gets connection wait timeout time--> <property name=" Maxwait "Val Ue= "60000"/> <!--Configure how often the interval is detected to detect idle connections that need to be closed, in milliseconds--> <property name= "Timebetweenevictionrunsmillis "Value=" 60000/> <!--Configures the minimum time that a connection is to survive 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 Pscach E, and specify the size of the Pscache on each connection--> <property name= "poolpreparedstatements" value= "true"/> <property name= "MaxP" Oolpreparedstatementperconnectionsize "value="/> <!--configuration monitor statistics intercept filters, after removing the monitor interface SQL cannot be counted--> <prope Rty name= "Filters" value= "stat"/> </bean>
Currently such a configuration has been able to 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:
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
Access http://ip:port/projectName/druid/index.html after configuration.
Through the above configuration, we have been able to reach the use of connection pooling and monitoring, this is just a simple introduction, if you want more detailed learning, but also a lot of exchanges forum.