How to solve exceptions caused by DBCP connection idle for more than 8 hours

Source: Internet
Author: User

MySQLThe default"Wait_timeout"Is 8 hours, that is, if a connection is idle for more than 8 hours, Mysql will automatically disconnect the connection. If connections is idle for more than 8 hours, Mysql disconnects it, whileDBCPIt is unknown that the connection has expired. If a Client requests a connection, DBCP will provide the Connection to the Client, which will cause an exception.

In mysql configuration, the wait_timeout value of my. cnf must be greater than or equal to the idle_timeout value of the connection pool. Otherwise, mysql closes the connection after the wait_timeout time. However, the connection pool considers the connection to be available, which causes an exception.

 
 
  1. org.apache.jasper.JasperException:javax.servlet.ServletException:  
  2.  
  3. javax.servlet.jsp.JspException::CommunicationslinkfailureLastpacketsenttotheserverwas1msago.org.apache.jasper.servlet.JspServletWrapper.handleJspExceptionJspServletWrapper.java:522)  
  4.  
  5. org.apache.jasper.servlet.JspServletWrapper.serviceJspServletWrapper.java:398)  
  6.  
  7. org.apache.jasper.servlet.JspServlet.serviceJspFileJspServlet.java:342)  
  8.  
  9. org.apache.jasper.servlet.JspServlet.serviceJspServlet.java:267)  
  10.  
  11. javax.servlet.http.HttpServlet.serviceHttpServlet.java:717) 

DBCP connection pool description: driverClassNameurlusernamepassword the four above are drivers, connection strings, usernames, and passwords respectively.

The maximum number of connections supported by the maxActive connection pool.

The maximum number of idle maxIdle connections in the maxIdle connection pool.

The minimum number of idle maxIdle connections in the minIdle connection pool.

InitialSize indicates the number of initial connections.

The new request wait time, in milliseconds, when the connection in the maxWait connection pool is used up.

TimeBetweenEvictionRunsMillis and minEvictableIdleTimeMillis are used together. Each timeBetweenEvictionRunsMillis checks idle connections in the connection pool in milliseconds, and disconnects connections with idle time exceeding minEvictableIdleTimeMillis in milliseconds, until the number of connections in the connection pool reaches minIdle, it is good to add these two parameters.

MinEvictableIdleTimeMillis idle time in the connection pool.

Millisecond removeAbandonedtrue, false, whether to clear.

RemoveAbandonedTimeout seconds are not used for active connections. After cleaning, the connection pool is not put back.

The maximum idle time of the removeAbandonedTimeout active connection.

LogAbandonedtrue, false: whether to print messages when the connection pool recovers idle active connections.

The minEvictableIdleTimeMillis and removeAbandonedTimeout parameters are inconsistent with the connection objects.

MinEvictableIdleTimeMillis is the connection object in the connection pool.

RemoveAbandonedTimeout is applicable to unclosed active connections.

After understanding the MySQL connection details, we can easily find out the errors when we encounter connection exceptions in the future. This article introduces you here. Thank you!

Related Article

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.