【发布时间】:2026-01-05 23:10:01
【问题描述】:
我正在使用 Mybatis 查询 MySQL DB 的后端 Web 服务器。
网络服务器只在有限的(但不是固定的)时间段内请求,所以几乎每天我都会收到如下警告日志。
pooled.PooledDataSource: Execution of ping query 'SELECT 1' failed: The last packet successfully received from the server was 51,861,027 milliseconds ago. The last packet sent successfully to the server was 51,861,027 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.
autoReconnect=true (Why does autoReconnect=true not seem to work?) 看起来很接近我的问题,但这不是我所期望的。
我想知道当它处于空闲状态一段时间(可能是 1 小时)时,是否可以通过 ping 它来建立连接永不超时。
由于Mybatis使用的是连接池,所以很难强制ping指定的空闲连接并使其永不超时。
我在谷歌上做了一些搜索,但看起来入侵 Mybatis 并不容易。
我的问题是:
- 对于这个问题是否有任何建议、参考或替代库?
或者
- 我是否有理由不尝试保持始终处于活动状态的连接? (潜在风险?违反最佳做法?等)
【问题讨论】:
-
使用连接池。