Druid Connection Pool Simple entry configuration __j2ee

Source: Internet
Author: User
Tags connection pooling

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.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.