• 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

  • 相关阅读:
    svn使用教程
    软件工程课程设计分组与选题名单
    解决自己的提问
    <构建之法>第十三章到十七章有感以及这个项目读后感
    <构建之法>第十一章、十二章有感
    关于C语言打印string类字符串的问题
    单链表
    8、判断三角形ABC中是否有点D
    7、完整版的strcpy函数
    6、旋转数组的最小数字
  • 原文地址:https://www.cnblogs.com/webttt/p/11102178.html
Copyright © 2020-2023  润新知