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



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

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

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

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

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

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

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

该代码将获取管理客户端,允许您访问查询MBeans。 拥有 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();
}

}

最新更新