zoukankan      html  css  js  c++  java
  • 【Tomcat】tomcat报连接超时错误

    程序一直报这个错误

    [getui-server][ERROR] [2016-03-17 10:50:00] getui.task.HftMongoInfoTask.execute(137) | --HftMongoInfoTask-error-org.springframework.dao.RecoverableDataAccessException: PreparedStatementCallback; SQL [select mid from test_info where cid = 9]; Communications link failure
    
    The last packet successfully received from the server was 250,825 milliseconds ago.  The last packet sent successfully to the server was 0 milliseconds ago.; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
    
    The last packet successfully received from the server was 250,825 milliseconds ago.  The last packet sent successfully to the server was 0 milliseconds ago.

    百度搜了很多,很多人都遇到过这个错误,大部分都是使用连接池方式时才会出现这个问题,短连接应该很难出现这个问题。这个问题的原因:

    MySQL服务器默认的“wait_timeout”是28800秒即8小时,意味着如果一个连接的空闲时间超过8个小时,MySQL将自动断开该连接,而连接池却认为该连接还是有效的(因为并未校验连接的有效性),当应用申请使用该连接时,就会导致上面的报错。

    1.按照错误的提示,可以在JDBC URL中使用autoReconnect属性,实际测试时使用了autoReconnect=true&failOverReadOnly=false,不过并未起作用,使用的是5.1版本,可能真像网上所说的只对4之前的版本有效。

    2.没办法,只能修改MySQL的参数了,wait_timeout最大为31536000即1年,在my.cnf中加入:

    [mysqld]

    wait_timeout=31536000

    interactive_timeout=31536000

    3.以上方法试过了,都不行。

    结果是我的连接池问题,dbcp链接数据库超时,增加一个自定检测释放,就可以了。

    下面是两个我解决问题的链接,希望对遇到这个问题的伙伴有帮助。

  • 相关阅读:
    ZOJ 3818 Pretty Poem
    HDU 4597 Play Game
    HDU 4497 GCD and LCM
    CSU 1335 高桥和低桥
    UVA 10791 Minimum Sum LCM
    CSU 1119 Collecting Coins
    CSU 1120 病毒
    UVA 12169 Disgruntled Judge
    HDU 1301 Jungle Roads
    POJ 1258 Agri-Net
  • 原文地址:https://www.cnblogs.com/anny0404/p/5290857.html
Copyright © 2011-2022 走看看