Skip to content

Commit f53d890

Browse files
author
Nico Verwer
committed
report db-connection pool info when threads are waiting
1 parent de9a1b5 commit f53d890

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

extensions/modules/sql/src/main/java/org/exist/xquery/modules/sql/GetConnectionFunction.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
package org.exist.xquery.modules.sql;
3434

3535
import com.zaxxer.hikari.HikariDataSource;
36+
import com.zaxxer.hikari.HikariPoolMXBean;
3637
import org.apache.logging.log4j.LogManager;
3738
import org.apache.logging.log4j.Logger;
3839

@@ -173,18 +174,27 @@ private Connection getConnectionFromPool(final Sequence[] args) throws XPathExce
173174
throw new XPathException(this, "There is no configured connection pool named: " + poolName);
174175
}
175176

177+
Connection connection = null;
176178
try {
177179
if (args.length == 3) {
178180
final String username = args[1].getStringValue();
179181
final String password = args[2].getStringValue();
180-
return pool.getConnection(username, password);
182+
connection = pool.getConnection(username, password);
181183
} else {
182-
return pool.getConnection();
184+
connection = pool.getConnection();
183185
}
184186
} catch (final SQLException sqle) {
185187
LOGGER.error("sql:get-connection-from-pool() Cannot retrieve connection from pool: " + poolName, sqle);
186188
throw new XPathException(this, "sql:get-connection-from-pool() Cannot retrieve connection from pool: " + poolName, sqle);
187189
}
190+
191+
HikariPoolMXBean poolBean = pool.getHikariPoolMXBean();
192+
193+
if (poolBean.getThreadsAwaitingConnection() > 0) {
194+
LOGGER.info("getConnectionFromPool("+poolName+"), "+poolBean.getActiveConnections()+" active, "+poolBean.getIdleConnections()+" available, "+poolBean.getThreadsAwaitingConnection()+" waiting, "+poolBean.getTotalConnections()+" total connections.");
195+
}
196+
197+
return connection;
188198
}
189199

190200
private static FunctionSignature[] functionSignatures(final String name, final String description, final FunctionReturnSequenceType returnType, final FunctionParameterSequenceType[][] variableParamTypes) {

0 commit comments

Comments
 (0)