gpt4 book ai didi

java - 数据库在等待空闲可用连接时超时

转载 作者:搜寻专家 更新时间:2023-10-30 22:11:01 24 4
gpt4 key购买 nike

我正在使用 Java Play 框架版本 2.3.7,当我尝试调用存储过程时抛出此异常:

[error] application - An error has been occurred tryning loading the Pictures by Gift. Timed out waiting for a free available connection. java.sql.SQLException: Timed out waiting for a free available connection. at com.jolbox.bonecp.DefaultConnectionStrategy.getConnectionInternal(DefaultConnectionStrategy.java:88) ~[bonecp-0.8.0.RELEASE.jar:na] at com.jolbox.bonecp.AbstractConnectionStrategy.getConnection(AbstractConnectionStrategy.java:90) ~[bonecp-0.8.0.RELEASE.jar:na] at com.jolbox.bonecp.BoneCP.getConnection(BoneCP.java:553) ~[bonecp-0.8.0.RELEASE.jar:na] at com.jolbox.bonecp.BoneCPDataSource.getConnection(BoneCPDataSource.java:131) ~[bonecp-0.8.0.RELEASE.jar:na] - at play.api.db.DBApi$class.getConnection(DB.scala:66) ~[play-jdbc_2.11-2.3.7.jar:2.3.7]

Java 代码:

CallableStatement cst = null;
ResultSet rs = null;
Connection conn = DB.getConnection();
List<Picture> pictures = null;
try {
conn = DB.getConnection();
for (Gift gift : giftList) {
cst = conn.prepareCall("{CALL sp_set_pictures_LOAD_PICTURES_BY_GIFT(?)}");
cst.setInt(1, gift.getId());
rs = cst.executeQuery();
if (rs.next()) {
pictures = new ArrayList<Picture>();
do {
Picture p = new Picture(rs.getInt(1));
pictures.add(p);
} while (rs.next());
gift.setPictures(pictures);
}
}
} catch (Exception e) {
Logger.error("An error has been occurred tryning loading the Pictures by Gift.\n" + e.getMessage(), e);
} finally {
if (cst != null)
cst = null;
close(conn);
}

应用程序配置文件:

db.default.autocommit=true
db.default.isolation=READ_COMMITTED
db.default.partitionCount=2
db.default.maxConnectionsPerPartition=5
db.default.minConnectionsPerPartition=5
db.default.acquireIncrement=1
db.default.acquireRetryAttempts=10
db.default.acquireRetryDelay=5 seconds
db.default.connectionTimeout=20 second
db.default.idleMaxAge=10 minute
db.default.idleConnectionTestPeriod=5 minutes
db.default.initSQL="SELECT 1"
db.default.logStatements=false
db.default.maxConnectionAge=1 hour
db.default.queryExecuteTimeLimit=1 second

最佳答案

您调用 DB.getConnection() 两次。也许正因为如此,JDBC 驱动程序创建了 2 个连接,但您只关闭了第二个连接。

关于java - 数据库在等待空闲可用连接时超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29081125/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com