druid-database connection pool with monitoring function

Source: Internet
Author: User

JDBC needs to operate the database through the connection database connection. The creation of a database connection is expensive, and we cannot create a database connection every time an SQL statement is executed, typically through a database connection pool, but the MySQL database has a 8-hour problem (if the database connection is not used for more than 8 hours, MySQL automatically disconnects the connection), After more than 8 hours, the connection obtained from the connection pool may have been invalidated, resulting in an exception that can be resolved by setting the effective time of the connection in the configuration file of the connection pool, although the connection pool is more beneficial than harmful. At present the more popular connection pool has dbcp, c3p0 and so on. Recently looked under Ali's Open source project Druid, it is not only a database connection pool, also provides the monitoring function, it has the following advantages: 1, very convenient replacement dbcp and C3P0 connection pool, 2, performance than DBCP, C3P0 and other connection pool good, 3, the use of Filter-chain responsibility chain model, It is convenient to add monitoring function and encrypt the database user name and password.

by configuring in Web. xml

<servlet> <servlet-name>DruidStatView</servlet-name> <servlet-class>com.alibaba.druid.su pport.http.statviewservlet</servlet-class> </servlet> <servlet-mapping> <servlet-name> Druidstatview</servlet-name> <url-pattern>/druid/*</url-pattern> </servlet-mapping>

You can count the execution time, number of executions, and so on for the SQL statement. configuring in Web. xml

<filter> <filter-name>DruidWebStatFilter</filter-name> <filter-class> Com.alibaba.druid.support.http.webstatfilter</filter-class> <init-param> <param-name>exclusion S</param-name> <param-value>*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*</param-value> </ini t-param> </filter> <filter-mapping> <filter-name>DruidWebStatFilter</filter-name> <u Rl-pattern>/*</url-pattern> </filter-mapping>

Can count the number of requests per request, request time and other data, Also in the built-in monitoring page weburi-detail.html, view the Jdbcpoolconnectionopencount and Jdbcpoolconnectionclosecount properties, if not equal, indicating a leak in the connection. Some of the specific parameter configurations can refer to Https://github.com/alibaba/druid.

druid-database connection pool with monitoring function

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.