Java JDBC连接池监视GlassFish

Java JDBC连接池监视GlassFish,java,jdbc,glassfish,Java,Jdbc,Glassfish,我试图找到一个设置,通过该设置,每当出现“错误分配连接”或“连接已关闭”之类的错误时,连接池监视信息就会出现在server.log中 我发现一些人在谈论这一点,但他们从GUI的角度提到了这一点。但是,我希望对连接池本身进行设置,以便在日志中显示连接池监视信息 有人知道这样的环境吗 在Sun app Server 8.X上,它以前是性能监视器,我不知道这是否对您有帮助。。。。但是您可以通过jmx查询连接池监控信息。 此代码将打印appserver中所有连接池的最大池大小和已用连接数(您可以从MBe

我试图找到一个设置,通过该设置,每当出现“错误分配连接”或“连接已关闭”之类的错误时,连接池监视信息就会出现在server.log中

我发现一些人在谈论这一点,但他们从GUI的角度提到了这一点。但是,我希望对连接池本身进行设置,以便在日志中显示连接池监视信息

有人知道这样的环境吗


在Sun app Server 8.X上,它以前是性能监视器,我不知道这是否对您有帮助。。。。但是您可以通过jmx查询连接池监控信息。 此代码将打印appserver中所有连接池的最大池大小和已用连接数(您可以从MBean中提取更多内容):

MBeanServerConnection conn=getMbeanServerConnection();
//在jmx寄存器中搜索指定的bean
设置connectorPoolSet=conn.queryMBeans(新对象名(“*:type=jdbc连接池,*”),null);
Map configMap=newhashmap();
Map monitorMap=新的HashMap();
//获取为搜索找到的每个配置和监视对象的映射
for(ObjectInstance oi:connectorPoolSet){
字符串名称=oi.getObjectName().getKeyProperty(“名称”);
//如果mbean的类别是config-将其放在config映射中-否则,如果它是monitor
//将其放置在监视器地图中。
字符串category=oi.getObjectName().getKeyProperty(“类别”);
如果(“配置”.equalsIgnoreCase(类别)){
configMap.put(name,oi.getObjectName());
}else if(“监视器”。等效信号情况(类别)){
monitorMap.put(name,oi.getObjectName());
}
}
//迭代找到的配置和监视MBean对
for(字符串名称:configMap.keySet()){
ObjectName configObjectName=configMap.get(名称);
ObjectName monitorObjectName=monitorMap.get(name);
如果(monitorObjectName==null){
//找不到监视器-引发异常或其他问题
}
int maxPoolSizeVal=getAttributeValue(conn,configObjectName,“最大池大小”);
int connectionsInUse=getAttributeValue(conn,monitorObjectName,“numconused current”);
System.out.println(名称+“->最大池大小:”+maxPoolSizeVal);
System.out.println(name+“->正在使用的连接:”+connectionsInUse);
}
    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);


    }