The last packet successfully received from the server was 964,697 milliseconds ago.

接口报错

The last packet sent successfully to the server was 964,698 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.;

配置信息

1)使用druid连接池
2)wait_timeout=300(禁止修改)
3)连接已配置autoReconnect=true

解决方案

新增DruidDataSource配置项

        DruidDataSource druidDataSource = new DruidDataSource();
        druidDataSource.setValidationQuery("select 1");
        druidDataSource.setTestWhileIdle(true);
        return druidDataSource;

Druid参数说明

validationQuery = “SELECT 1”
#验证连接是否可用,使用的SQL语句

testWhileIdle = “true”
#指明连接是否被空闲连接回收器(如果有)进行检验.如果检测失败,则连接将被从池中去除.
每30秒,取出3条连接(默认值)使用validationQuery = “SELECT 1” 中的SQL进行测试 ,测试不成功就销毁连接。销毁连接后,连接数量就少了,如果小于minIdle数量,就新建连接。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值