DBCP reports an error because MySQL closes the connection automatically.

Source: Internet
Author: User

After the page is not operated for a long time, the program will report an error when the page is operated again. The exception is as follows:

 

Com. mysql. jdbc. exceptions. jdbc4.CommunicationsException: Communications link failure

Thelast packet successfully received from the server was 8,064,672 millisecondsago. The last packet sent successfully to the server was 8,064,672 millisecondsago.
At sun. reflect. NativeConstructorAccessorImpl. newInstance0 (Native Method)
Atsun. reflect. NativeConstructorAccessorImpl. newInstance (NativeConstructorAccessorImpl. java: 39)
Atsun. reflect. delegatingconstruct%cessorimpl. newInstance (delegatingconstruct%cessorimpl. java: 27)
At java. lang. reflect. Constructor. newInstance (Constructor. java: 513)
At com. mysql. jdbc. Util. handleNewInstance (Util. java: 409)
At com. mysql. jdbc. SQLError. createCommunicationsException (SQLError. java: 1122)
At com. mysql. jdbc. MysqlIO. send (MysqlIO. java: 3317)
At com. mysql. jdbc. MysqlIO. sendCommand (MysqlIO. java: 1941)
At com. mysql. jdbc. MysqlIO. sqlQueryDirect (MysqlIO. java: 2114)
At com.mysql.jdbc.ConnectionImpl.exe cSQL (ConnectionImpl. java: 2696)
Atcom.mysql.jdbc.PreparedStatement.exe cuteInternal (PreparedStatement. java: 2105)
At com.mysql.jdbc.PreparedStatement.exe cuteQuery (PreparedStatement. java: 2264)
At org.apache.commons.dbcp.DelegatingPreparedStatement.exe cuteQuery (DelegatingPreparedStatement. java: 96)
Atorg.apache.commons.dbcp.DelegatingPreparedStatement.exe cuteQuery (DelegatingPreparedStatement. java: 96)
Atorg.apache.commons.dbcp.DelegatingPreparedStatement.exe cuteQuery (DelegatingPreparedStatement. java: 96)
...
Caused by: java.net. SocketException: Connection reset by peer: socket writeerror
At java.net. SocketOutputStream. socketWrite0 (Native Method)
At java.net. SocketOutputStream. socketWrite (SocketOutputStream. java: 92)
At java.net. SocketOutputStream. write (SocketOutputStream. java: 136)
At java. io. BufferedOutputStream. flushBuffer (BufferedOutputStream. java: 65)
At java. io. BufferedOutputStream. flush (BufferedOutputStream. java: 123)
At com. mysql. jdbc. MysqlIO. send (MysqlIO. java: 3298)
... 34 common frames omitted

 

The reason is that the timeout time for DBCP connection persistence is longer than that for MySQL connection. The wait_timeout value in mysql configuration must be greater than or equal to the idle_timeout value of the connection pool. Otherwise, mysql will close the connection after the wait_timeout time. However, the connection pool still considers the connection to be available, resulting in an exception.

 

Connect to the server through the MySQL client to view the current configuration.

 

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.