zoukankan      html  css  js  c++  java
  • dbcp连接报错:The last packet successfully received from the server was 50,664,909 milliseconds ago.

    dbcp连接报错:The last packet successfully received from the server was 50,664,909 milliseconds ago.  The last packet sent successfully to the server was 50,664,912 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.

    原因:Mysql 数据库连接8小时后若没有连接会自动断开。

    分析:

    方法一:查看数据库中连接时间   mysql>SHOW VARIABLES LIKE '%_timeout%' 

    wait_timeout 等待时间为8小时,网上有解决方案说修改这个时间。

    SET GLOBAL interactive_timeout=31536000;
    SET GLOBAL wait_timeout=31536000;

    再用上面的语句查看发现没有改变,此时用另一个语句查看:

    mysql>SHOW GLOBAL VARIABLES LIKE '%_timeout%'

    发现wait_timeout最大只能设置到2147183s,如果程序在这个时间内一定有连接可以使用,但是我的程序不是。

    如果这个时间可以的直接修改mysql配置文件,上面的语句设置mysql重启会失效。

    [mysqld]

    wait_timeout=31536000

    interactive_timeout=31536000

    重启生效,需要同时修改这两个参数。

    解决:

    方法二:修改dbcp.properties配置文件

    增加以下属性

    validationQuery=select current_date()
    
    #请求之前和之后进行连接池测试
    testOnBorrow=false
    testOnReturn=false
    
    #空闲时是进行验证,检查对象是否有效
    testWhileIdle=true
    
    #超过removeAbandonedTimeout时间后,是否进行没用连接(废弃)的回收(默认为false,调整为true)
    removeAbandoned=true
    #超过时间限制,回收没有用(废弃)的连接(默认为 300秒)
    removeAbandonedTimeout=90
    
    #秒对连接池进行一次检测,将对象闲置时间超过minEvictableIdleTimeMillis秒的对象进行销毁,创建新的对象来取代
    timeBetweenEvictionRunsMillis=30000
    minEvictableIdleTimeMillis=1800000
    
    
    #设定在进行后台对象清理时,每次检查几个链接。默认值是3.
    numTestsPerEvictionRun=20
    

      参考:https://blog.csdn.net/liuyangvoid/article/details/25975157

                      https://blog.csdn.net/pandajava/article/details/41946251

  • 相关阅读:
    安卓逆向5.Android Studio JNI静态注册(C++和Java互操作)
    安卓逆向二
    ASP.Net Core Web 在IIS下的发布流程
    Android Studio安装记录
    Vistual studio智能提示不显示或者显示为英文的解决办法
    (转)程序语言理论的学习对于程序员教育的作用
    普通用户ssh无密码登录设置
    (转)完全用GNU/Linux工作 by 王珢
    (转)谁是真正的程序语言专家
    java操作XML
  • 原文地址:https://www.cnblogs.com/webttt/p/11102178.html
Copyright © 2011-2022 走看看