mirror of
https://github.com/qaiu/netdisk-fast-download.git
synced 2026-06-10 15:37:28 +00:00
fix(resource): JDBCPoolInit 实现 AutoCloseable 添加 close() 方法
原代码单例模式无关闭方法,应用退出时数据库连接池无法释放。 改为: - 实现 AutoCloseable 接口 - 添加 close() 方法关闭连接池 - 关闭后将 pool 置 null 防止重复关闭
This commit is contained in:
@@ -17,7 +17,7 @@ import org.slf4j.LoggerFactory;
|
||||
*
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
*/
|
||||
public class JDBCPoolInit {
|
||||
public class JDBCPoolInit implements AutoCloseable {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(JDBCPoolInit.class);
|
||||
|
||||
@@ -101,4 +101,16 @@ public class JDBCPoolInit {
|
||||
synchronized public JDBCPool getPool() {
|
||||
return pool;
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭连接池,释放数据库资源
|
||||
*/
|
||||
@Override
|
||||
public synchronized void close() {
|
||||
if (pool != null) {
|
||||
pool.close();
|
||||
LOGGER.info("数据库连接池已关闭: URL={}", url);
|
||||
pool = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user