【问题标题】:How to get number of used/opened connections in a MQ Connection factory configured in WebSphere Application Server如何在 WebSphere Application Server 中配置的 MQ 连接工厂中获取已使用/打开的连接数
【发布时间】:2020-02-07 07:20:32
【问题描述】:

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

【问题讨论】:

    标签: java websphere ibm-mq


    【解决方案1】:

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

    DISPLAY CONN(*) TYPE(ALL) ALL WHERE(OBJNAME EQ reply-q-name)
    

    这将显示所有连接和所有打开的句柄。

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

    【讨论】:

      【解决方案2】:

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

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

      代码将获取管理员客户端,让您可以访问 queryMBean。拥有 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();
          }
      
      
      }
      

      【讨论】:

        猜你喜欢
        • 2014-09-05
        • 1970-01-01
        • 2012-10-09
        • 2011-09-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-08-28
        相关资源
        最近更新 更多