Java 如何获取WebSphere Application Server中配置的MQ连接工厂中已使用/打开的连接数

Java 如何获取WebSphere Application Server中配置的MQ连接工厂中已使用/打开的连接数,java,websphere,ibm-mq,Java,Websphere,Ibm Mq,我有一个java应用程序运行在WebSphere8.5.5.12服务器上。我通过MQ连接到其他应用程序。我遇到了应用程序的性能问题,发现每当MQ应答超时时,队列连接都没有正确关闭。我已经解决了这个问题。我计划增加特定队列连接工厂的最大连接数,并希望通过代码获得队列连接工厂中使用/打开的连接数,以便根据流量/容量相应增加最大连接数。任何线索都会很有帮助 要了解应用程序使用的连接数和打开的队列数,可以使用如下MQSC DISPLAY CONN命令:- DISPLAY CONN(*) TYPE(ALL

我有一个java应用程序运行在WebSphere8.5.5.12服务器上。我通过MQ连接到其他应用程序。我遇到了应用程序的性能问题,发现每当MQ应答超时时,队列连接都没有正确关闭。我已经解决了这个问题。我计划增加特定队列连接工厂的最大连接数,并希望通过代码获得队列连接工厂中使用/打开的连接数,以便根据流量/容量相应增加最大连接数。任何线索都会很有帮助

要了解应用程序使用的连接数和打开的队列数,可以使用如下MQSC DISPLAY CONN命令:-

DISPLAY CONN(*) TYPE(ALL) ALL WHERE(OBJNAME EQ reply-q-name)
这将显示所有连接和所有打开的句柄


您还可以使用名为PCF命令的编程接口发现完全相同的数据,尽管考虑到有多少优秀的MQ管理工具,我不确定您为什么需要像您所说的“通过代码”这样做?

要了解应用程序使用的连接数和打开的队列数,您可以像这样使用MQSC DISPLAY CONN命令:-

DISPLAY CONN(*) TYPE(ALL) ALL WHERE(OBJNAME EQ reply-q-name)
这将显示所有连接和所有打开的句柄


您还可以使用一个名为PCF命令的编程接口来发现完全相同的数据,尽管考虑到有多少优秀的MQ管理工具,我不确定您为什么需要像您所说的那样“通过代码”执行此操作?

对于问题的第二部分,如何根据负载更改最大连接数

我有一些使用数据源的示例代码,可以帮助回答您的问题。在我使用内置derby数据源name=的地方,可以将名称更改为队列连接工厂名称。如果需要查找,请将此jndi名称jdbc/内置derby数据源更改为队列连接工厂jndi名称

代码将获得管理客户端,使您能够访问queryMBeans。拥有mbean后,可以在服务器运行时动态更改最大连接数

@SuppressWarnings("unchecked")
public void AdminClientExample() 
{
    Object adminClient = null;

    // Need to set the properties, type, host and port, defaults likely will work for most
    Properties acProps = new Properties();
    acProps.setProperty(AdminClient.CONNECTOR_TYPE, AdminClient.CONNECTOR_TYPE_SOAP);
    acProps.setProperty(AdminClient.CONNECTOR_HOST, "localhost");
    acProps.setProperty(AdminClient.CONNECTOR_PORT, "8880");

    // Set if security is enabled
    //acProps.setProperty(AdminClient.CONNECTOR_SECURITY_ENABLED, "true");
    //acProps.setProperty(AdminClient.USERNAME, "userid");
    //acProps.setProperty(AdminClient.PASSWORD, "userid password");

    try 
    {
        adminClient = AdminClientFactory.createAdminClient(acProps);

    } 
    catch (Exception e)  
    {
        e.printStackTrace();
    }

    ObjectInstance obi = null;
    ObjectName obn = null;
    Set<ObjectInstance> s = null;
    try {
        // The two types to use are J2CConnectionFactory and DataSource if searching through a list of mbeans of that type.
        // type=J2CConnectionFactory
        // type=DataSource
        // obn = new ObjectName("WebSphere:type=DataSource,*");
        // s1 =((AdminClient)adminClient).queryMBeans(obn, null);   // search through s1

        // You can provide the name like this, 
        obn = new ObjectName("WebSphere:name=built-in-derby-datasource,*");
        s =((AdminClient)adminClient).queryMBeans(obn, null);
        // s should contain WebSphere:name=built-in-derby-datasource,process=server1,platform=dynamicproxy,node=DefaultNode01,JDBCProvider=Derby JDBC Provider (XA),diagnosticProvider=true,j2eeType=JDBCDataSource,J2EEServer=server1,Server=server1,version=9.0.0.11,type=DataSource,mbeanIdentifier=cells/DefaultCell01/resources.xml#DataSource_9007001,JDBCResource=Derby JDBC Provider (XA),cell=DefaultCell01,spec=1.0
    } catch (Exception e) {
        e.printStackTrace();
    }

    if (s == null) {
        System.out.println("Did not find MBeans querying for object name " + obn.toString());
        return;
    } else {
        obi = s.iterator().next();  
    }

    // Normally the application using the connection pool will have
    // already done the lookup which creates the objects
    // required to change maxConnections.  This lookup is only for
    // this example.
    InitialContext ctx;
    try {  
        ctx = new InitialContext();
        ctx.lookup("jdbc/built-in-derby-datasource");
    } catch (Exception e) {
        e.printStackTrace();
    }

    // show the connection pool contents
    Object [] parms =  null;
    String [] parmsTypes = null;
    try {
        String ss = (String) ((AdminClient)adminClient).invoke(obi.getObjectName(), "showPoolContents", parms, parmsTypes);
        System.out.println(ss);
    } catch (Exception e) {
        e.printStackTrace(); 
    }

    // get maxConnections
    try {
        Object maxConnections = ((AdminClient)adminClient).getAttribute(obi.getObjectName(), "maxConnections");
        System.out.println(maxConnections);
    } catch (Exception e) {
        e.printStackTrace();
    }

    // change the maxConnections to 11,
    try {
        Integer it = new Integer(11);
        Attribute at = new Attribute("maxConnections", it);
        ((AdminClient)adminClient).setAttribute(obi.getObjectName(), at );
    } catch (Exception e) {
        e.printStackTrace();
    }

    // show the connection pool contents, maxConnection now should be 11.
    // or you can use the get maxConnection to check
    // the changed value.
    try {
        String ss = (String) ((AdminClient)adminClient).invoke(obi.getObjectName(), "showPoolContents", parms, parmsTypes);
        System.out.println(ss);
        // or
        Object maxConnections = ((AdminClient)adminClient).getAttribute(obi.getObjectName(), "maxConnections");
        System.out.println(maxConnections);
    } catch (Exception e) {
        e.printStackTrace();
    }


}
@SuppressWarnings(“未选中”)
public void AdminClientExample()
{
对象adminClient=null;
//需要设置属性、类型、主机和端口,默认值可能适用于大多数情况
属性acProps=新属性();
setProperty(AdminClient.CONNECTOR\u类型,AdminClient.CONNECTOR\u类型\u SOAP);
setProperty(AdminClient.CONNECTOR_HOST,“localhost”);
acProps.setProperty(AdminClient.CONNECTOR_PORT,“8880”);
//设置是否启用了安全性
//acProps.setProperty(AdminClient.CONNECTOR_SECURITY_ENABLED,“true”);
//setProperty(AdminClient.USERNAME,“userid”);
//setProperty(AdminClient.PASSWORD,“userid密码”);
尝试
{
adminClient=AdminClientFactory.createAdminClient(acProps);
} 
捕获(例外e)
{
e、 printStackTrace();
}
ObjectInstance obi=null;
ObjectName obn=null;
设置s=null;
试一试{
//如果搜索该类型的MBean列表,则要使用的两种类型是J2CConnectionFactory和DataSource。
//类型=J2C连接工厂
//类型=数据源
//obn=newobjectname(“WebSphere:type=DataSource,*”);
//s1=((AdminClient)AdminClient.queryMBeans(obn,null);//搜索s1
//您可以提供这样的名称,
obn=newobjectname(“WebSphere:name=内置derby数据源,*”;
s=((AdminClient)AdminClient.queryMBeans(obn,null);
//应包含WebSphere:name=内置derby数据源、process=server1、platform=dynamicproxy、node=DefaultNode01、JDBCProvider=derby JDBC Provider(XA),diagnosticProvider=true,j2eeType=JDBCDataSource,J2EEServer=server1,Server=server1,version=9.0.0.11,type=DataSource,mbeanIdentifier=cells/DefaultCell01/resources.xml#DataSource_9007001,JDBCResource=Derby JDBC Provider(XA),cell=DefaultCell01,spec=1.0
}捕获(例外e){
e、 printStackTrace();
}
如果(s==null){
System.out.println(“未找到查询对象名称的MBeans”+obn.toString());
返回;
}否则{
obi=s.iterator().next();
}
//通常,使用连接池的应用程序将具有
//已完成创建对象的查找
//更改maxConnections是必需的。此查找仅适用于
//这个例子。
初始上下文ctx;
试试{
ctx=新的InitialContext();
查找(“jdbc/内置derby数据源”);
}捕获(例外e){
e、 printStackTrace();
}
//显示连接池内容
Object[]parms=null;
字符串[]parmsTypes=null;
试一试{
String ss=(String)((AdminClient)AdminClient.invoke(obi.getObjectName(),“showPoolContents”,parms,parmsTypes);
系统输出打印LN(ss);
}捕获(例外e){
e、 printStackTrace();
}
//获取最大连接数
试一试{
对象maxConnections=((AdminClient)AdminClient.getAttribute(obi.getObjectName(),“maxConnections”);
System.out.println(maxConnections);
}捕获(例外e){
e、 printStackTrace();
}
//将maxConnections更改为11,
试一试{
整数it=新的整数(11);
属性at=新属性(“maxConnections”,it);
((AdminClient)AdminClient.setAttribute(obi.getObjectName(),位于);
}捕获(例外e){
e、 printStackTrace();
}
//显示连接池内容,maxConnection现在应该是11。
//或者,您可以使用get-maxConnection进行检查
//更改的值。
试一试{
String ss=(String)((AdminClient)AdminClient.invoke(obi.getObjectName(),“showPoolContents”,parms,parmsTypes);
系统输出打印LN(ss);
//或
对象最大值