• mysql 数据库连接超时的问题 autoReconnect=true


    最近在使用spring-jdbc数据库连接管理时,出现一个奇怪问题,当天部署运行没问题,第二天再试就报以下异常问题

    org.springframework.dao.RecoverableDataAccessException: PreparedStatementCallback; SQL []; The last packet successfully received from the server was 56,799,849 milliseconds ago. The last packet sent successfully to the server was 56,799,850 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 56,799,849 milliseconds ago. The last packet sent successfully to the server was 56,799,850 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
    
    at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:99) ~[spring-jdbc-3.2.9.RELEASE.jar:3.2.9.RELEASE]
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72) ~[spring-jdbc-3.2.9.RELEASE.jar:3.2.9.RELEASE]
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80) ~[spring-jdbc-3.2.9.RELEASE.jar:3.2.9.RELEASE]
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:605) ~[spring-jdbc-3.2.9.RELEASE.jar:3.2.9.RELEASE]
    at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:849) ~[spring-jdbc-3.2.9.RELEASE.jar:3.2.9.RELEASE]
    at com.pyw.email.provider.dao.EmailDao.insert(EmailDao.java:39) ~[email-provider-1.1.0.jar:na]
    at com.pyw.email.provider.thread.EmailSendThread.run(EmailSendThread.java:63) ~[email-provider-1.1.0.jar:na]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_79]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_79]
    at java.lang.Thread.run(Thread.java:745) [na:1.7.0_79]
    Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 56,799,849 milliseconds ago. The last packet sent successfully to the server was 56,799,850 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.7.0_79]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) ~[na:1.7.0_79]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.7.0_79]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526) ~[na:1.7.0_79]
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:425) ~[mysql-connector-java-5.1.40.jar:5.1.40]
    at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:989) ~[mysql-connector-java-5.1.40.jar:5.1.40]
    at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3743) ~[mysql-connector-java-5.1.40.jar:5.1.40]
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2506) ~[mysql-connector-java-5.1.40.jar:5.1.40]
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2677) ~[mysql-connector-java-5.1.40.jar:5.1.40]
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2549) ~[mysql-connector-java-5.1.40.jar:5.1.40]
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861) ~[mysql-connector-java-5.1.40.jar:5.1.40]
    at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2073) ~[mysql-connector-java-5.1.40.jar:5.1.40]
    at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2009) ~[mysql-connector-java-5.1.40.jar:5.1.40]
    at com.mysql.jdbc.PreparedStatement.executeLargeUpdate(PreparedStatement.java:5098) ~[mysql-connector-java-5.1.40.jar:5.1.40]
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1994) ~[mysql-connector-java-5.1.40.jar:5.1.40]
    at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105) ~[commons-dbcp-1.4.jar:1.4]
    at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105) ~[commons-dbcp-1.4.jar:1.4]
    at org.springframework.jdbc.core.JdbcTemplate$3.doInPreparedStatement(JdbcTemplate.java:851) ~[spring-jdbc-3.2.9.RELEASE.jar:3.2.9.RELEASE]
    at org.springframework.jdbc.core.JdbcTemplate$3.doInPreparedStatement(JdbcTemplate.java:849) ~[spring-jdbc-3.2.9.RELEASE.jar:3.2.9.RELEASE]
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:589) ~[spring-jdbc-3.2.9.RELEASE.jar:3.2.9.RELEASE]
    ... 6 common frames omitted
    Caused by: java.net.SocketException: Broken pipe
    at java.net.SocketOutputStream.socketWrite0(Native Method) ~[na:1.7.0_79]
    at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:113) ~[na:1.7.0_79]
    at java.net.SocketOutputStream.write(SocketOutputStream.java:159) ~[na:1.7.0_79]
    at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82) ~[na:1.7.0_79]
    at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140) ~[na:1.7.0_79]
    at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3725) ~[mysql-connector-java-5.1.40.jar:5.1.40]
    ... 19 common frames omitted

    解决方法参考文献:
    http://blog.csdn.net/bluesnail216/article/details/15810119 
    http://www.cnblogs.com/mumuxinfei/p/5100757.html 

  • 相关阅读:
    在SQL中删除重复记录
    SQL语句生成SQLServer数据字典
    还原数据库时出现的问题
    Active Server Pages 错误 'ASP 0201'
    VS.NET新建项目时出现“两者需要映射到相同的服务器位置”
    cs0016: 未能写入输出文件“c:\windows\microsoft.net\***.dll”错误处理
    Svchost.exe进程详解
    5y5.us
    C# 中返回星期的函数
    怎样用C#实现完整文档打印功能
  • 原文地址:https://www.cnblogs.com/rgky/p/6092826.html
Copyright © 2020-2023  润新知