LOG: Using the Connector/j Connection property ' Autoreconnect=true ' to avoid this problem

Source: Internet
Author: User

Com.mysql.jdbc.CommunicationsException:The last packet successfully received from the server was58129 seconds ago.  The last packet sent successfully to the server were 58129 seconds ago, which is longer than the server configured value of ' Wait_timeout '. Should consider either expiring and/or testing connection validity before use in your application, increasing the Serv Er configured values for client timeouts, or using the Connector/j Connection property ' Autoreconnect=true ' to avoid this Problem.

Checked, it turned out to be a MySQL timeout setting problem
If the connection is idle for 8 hours (no database operation within 8 hours), MySQL will automatically disconnect and restart Tomcat.

Workaround:

The first: If you don't use Hibernate, add the parameter to the connection URL: autoreconnect=true

1 jdbc.url=jdbc:mysql://ipaddress:3306/database?autoreconnect=true& Autoreconnectforpools=true

The second type: with Hibernate, add the following attributes:

1 < Propertyname= "Connection.autoreconnect">True</ Property>2 < Propertyname= "Connection.autoreconnectforpools">True</ Property>3 < Propertyname= "Connection.is-connection-validation-required">True</ Property>

The third type: If you also use C3P0 to connect the pool:

1 < Propertyname= "Hibernate.c3p0.acquire_increment">1</ Property> 2 < Propertyname= "Hibernate.c3p0.idle_test_period">0</ Property> 3 < Propertyname= "Hibernate.c3p0.timeout">0</ Property>4 < Propertyname= "Hibernate.c3p0.validate">True</ Property>

The fourth type: the most difficult solution

Using connector/j to connect to the MySQL database, the program will report the following error when it is running for a long time:

Communications Link Failure,the Last packet successfully received by the server was * * * millisecond ago. The last packet successfully sent to the server was * * * * millisecond ago.

The error will also prompt you to modify Wait_timeout or use Connector/j's AutoReConnect property to avoid the error.

Later looked up some information, only to find that the problem encountered a lot of people, most of them are using the connection pool mode when this problem occurs, short connection should be difficult to appear this problem. The cause of this problem:

MySQL server default "Wait_timeout" is 28,800 seconds, or 8 hours, means that if a connection is idle for more than 8 hours, MySQL will automatically disconnect the connection, and the connection pool that the connection is still valid (because the validity of the connection is not verified), When the application uses the connection, it causes the error above.

⑴. Following the wrong prompts, you can use the AutoReConnect property in the JDBC URL, and the autoreconnect=true& Failoverreadonly=false is used in the actual test, but it doesn't work. Using the 5.1 version, it may really be as valid as what is said on the Internet only for versions prior to 4.

⑵. No way, can only modify the parameters of MySQL, wait_timeout maximum of 31536000 that is 1 years, in MY.CNF added:

[Mysqld]

wait_timeout=31536000

interactive_timeout=31536000

Restart takes effect, both parameters need to be modified at the same time.

Log: Using the Connector/j Connection property ' Autoreconnect=true ' to avoid this problem

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.