No operations allowed after connection closed 问题小记
环境
Spring Boot 2.x 数据库连接池默认Hikari,现有配置为默认配置
产生原因
日志是warn级别的:
Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@70ec1a35
(No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
根据提示知道是获取的数据库连接Connection不可用了,看一下获取连接的源码:
public Connection getConnection(final long hardTimeout) throws SQLException
{
suspendResumeLock.acquire();
final long startTime = currentTime();
try {
long timeout = hardTimeout;
do {
//获取连接
PoolEntry poolEntry = connectionBag.borrow(timeout, MILLISECONDS);
if (poolEntry == null) {
break; // We timed out... break and throw exception
}
final long now = currentTime()