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.
- org.apache.jasper.JasperException:javax.servlet.ServletException:
-
- javax.servlet.jsp.JspException::CommunicationslinkfailureLastpacketsenttotheserverwas1msago.org.apache.jasper.servlet.JspServletWrapper.handleJspExceptionJspServletWrapper.java:522)
-
- org.apache.jasper.servlet.JspServletWrapper.serviceJspServletWrapper.java:398)
-
- org.apache.jasper.servlet.JspServlet.serviceJspFileJspServlet.java:342)
-
- org.apache.jasper.servlet.JspServlet.serviceJspServlet.java:267)
-
- 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!