Cause: one day, my colleague's project connection pool burst
At first, I thought there was a long-running sql, but after checking the DB, I found that there was no such sql at all
Then I wonder if it is the calling of the third-party interface, which is suspended or not closed due to timeout. After calling the code, I found that several third-party interfaces are also normal
Seeing that the hair on his colleague's head is getting less and less, he finally thought of using the monitoring method, so he asked the company's boss. After configuration, it was quick and easy to start. The effect was immediate, and the problem was also found. It was originally caused by a BatchInsert interface
In this mass submission, colleagues submit by batch in the form of sqlSessionFactory. The problem is that the colleagues did not close the Session after submitting. It is equivalent to occupying and suspending a connection every time
The code has been on for more than a year, and almost every week the business will operate three or four times. But it's OK. Because colleagues send versions every week, and every time the server is restarted, the connection pool will be reset. So I didn't find that until the business operated more than ten times in one time in the last few days, the connection pool burst
The focus of this article is how to configure druid monitor
The springBoot project we used, the company's framework, (should be similar to each other), is configured as follows
1. Add dependency first
<dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>1.1.2</version> </dependency>
2. In the DB configuration class, add the following configurations
public class Dbconfig { /** Original configuration */ @Bean("dataSource") @Primary public DataSource dataSource() { //Configure database account password connection and so on //There are more than 30 minutes, which will be forced to recycle. It is recommended not to open //Prevent connection leakage dataSource.setRemoveAbandoned(removeAbdon); //Recycle connection if not used for 30 minutes //Print log of forced recycle connections dataSource.setLogAbandoned(jdbcLogAbdon); //Add filter, example below try { dataSource.setFilters(filters); } catch (SQLException e) { LogHelper.commonerror("druid configuration initialization filter", e); } } @Bean public ServletRegistrationBean druidServlet() { ServletRegistrationBean reg = new ServletRegistrationBean(); reg.setServlet(new StatViewServlet()); //Path to the URL accessed reg.addUrlMappings("/druid/*"); //The login account password can be configured in the configuration center reg.addInitParameter("loginUsername", loginUsername); reg.addInitParameter("loginPassword", loginPassword); reg.addInitParameter("logSlowSql", logSlowSql); return reg; } //Register filter @Bean public FilterRegistrationBean filterRegistrationBean() { FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(); filterRegistrationBean.setFilter(new WebStatFilter()); filterRegistrationBean.addUrlPatterns("/*"); filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"); filterRegistrationBean.addInitParameter("profileEnable", "true"); return filterRegistrationBean; } )
3. Add configuration file without configuration
spring.datasource.login.username=admin spring.datasource.login.password=admin123 spring.datasource.logSlowSql=true
4. After starting the project, enter the URL ip:port / Project path / druid/login.html You can see it by entering the account code