MySQL 8-hour issue

Source: Internet
Author: User

In MySQL database, by default, if a connection is idle for more than 8 hours, the connection will be closed on the database side, and the data source does not know that the connection has been closed by the database, and when this useless connection is given to DAO, an exception is generated.

In spring, if the data source is configured with DBCP

If you are using the default configuration of DBCP, you will not incur a 8-hour problem because each data source will be checked before it is connected to DAO, but this can affect efficiency

A better approach is to:

    <BeanID= "Mysql_datasource"class= "Org.apache.commons.dbcp.BasicDataSource"Destroy-method= "Close"P:driverclassname= "${driverclassname}"P:url= "${url}"P:username= "${username_mysql}"P:password= "${password}"P:testonborrow= "false"P:testwhileidle= "true"P:timebetweenevictionrunsmillis= "27000000"P:validationquery= "Select 1"/>
P:timebetweenevictionrunsmillis is  less than 8 hours in milliseconds, but this 8 hour can also be configured with the Interactive-timeout parameter in MySQL, so in configuration p: Timebetweenevictionrunsmillis, you need to know the value of the Interactive-timeout setting first

MySQL 8-hour issue

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.