fix connection pool bug

This commit is contained in:
Looly 2025-06-09 16:41:45 +08:00
parent b68e180ad5
commit 7c2746c76a
2 changed files with 15 additions and 1 deletions

View File

@ -35,6 +35,9 @@ import java.util.Properties;
public class PooledConnection extends ConnectionWrapper { public class PooledConnection extends ConnectionWrapper {
private final PooledDataSource dataSource; private final PooledDataSource dataSource;
/**
* 仅用于记录连接在池中的状态如归还到池中为close状态从池中拿出需调用{@link #open()}变为可用状态
*/
private boolean isClosed = false; private boolean isClosed = false;
/** /**
@ -99,6 +102,17 @@ public class PooledConnection extends ConnectionWrapper {
return this.isClosed; return this.isClosed;
} }
/**
* 打开连接<br>
* 仅用于从连接池中拿出时调用使链接变为可用
*
* @return this
*/
PooledConnection open() {
this.isClosed = false;
return this;
}
/** /**
* 销毁连接即彻底关闭并丢弃连接 * 销毁连接即彻底关闭并丢弃连接
*/ */

View File

@ -86,7 +86,7 @@ public class PooledDataSource extends AbstractDataSource {
@Override @Override
public PooledConnection getConnection() throws SQLException { public PooledConnection getConnection() throws SQLException {
return connPool.borrowObject(); return connPool.borrowObject().open();
} }
@Override @Override