gpt4 book ai didi

java - JDBC 连接池监控 GlassFish

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:41:11 26 4
gpt4 key购买 nike

我正在尝试找到一个设置,每当发生“错误分配连接”或“连接关闭”等错误时,连接池监视信息就会出现在 server.log 中。

我找到了一些 blog entries谈论这个但他们从 GUI 角度提到它。但是,我想要连接池本身的设置,以便定期在日志中显示连接池监视信息。

有人知道这样的设置吗?

在 Sun app Server 8.X 上它曾经是 perf-monitor

最佳答案

我不知道这是否对你有帮助....但你可以通过jmx查询连接池监控信息。此代码将打印应用服务器中所有连接池的最大池大小和已用连接数(您可以从 MBean 中提取更多内容):

    MBeanServerConnection conn = getMbeanServerConnection();

//search the jmx register for the specified beans
Set<ObjectInstance> connectorPoolSet = conn.queryMBeans(new ObjectName("*:type=jdbc-connection-pool,*"), null);
Map<String , ObjectName> configMap = new HashMap<String, ObjectName>();
Map<String , ObjectName> monitorMap = new HashMap<String, ObjectName>();

//get a map of each config & monitor object found for the search
for(ObjectInstance oi : connectorPoolSet) {
String name = oi.getObjectName().getKeyProperty("name");

//if the category of the mbean is config - put it in the config map - else if it is monitor
//place it in the monitor map.
String category = oi.getObjectName().getKeyProperty("category");
if("config".equalsIgnoreCase(category)) {
configMap.put(name, oi.getObjectName());
} else if("monitor".equalsIgnoreCase(category)){
monitorMap.put(name, oi.getObjectName());
}
}

//iterate the pairs of config & monitor mbeans found
for(String name : configMap.keySet()) {

ObjectName configObjectName = configMap.get(name);
ObjectName monitorObjectName = monitorMap.get(name);
if(monitorObjectName == null) {
//no monitor found - throw an exception or something
}

int maxPoolSizeVal = getAttributeValue(conn, configObjectName, "max-pool-size");
int connectionsInUse = getAttributeValue(conn, monitorObjectName, "numconnused-current");

System.out.println(name + " -> max-pool-size : " + maxPoolSizeVal);
System.out.println(name + " -> connections in use : " + connectionsInUse);


}

关于java - JDBC 连接池监控 GlassFish,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2985786/

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