[英]Creating thread dumps of a remote jvm programatically
I have been trying to invoke an operation on ThreadMXBean in a remote jvm. 我一直在尝试在远程jvm中的ThreadMXBean上调用操作。 The code snippet I used invoke the operation is below
我用来调用该操作的代码段如下
bean = new ObjectName("java.lang:type=Threading");
memoryInfo = RemoteConnector.getRemote().getMBeanInfo(bean);
RemoteConnector.getRemote().getObjectInstance(bean);
MBeanOperationInfo [] mBeanAttributeInfos = memoryInfo.getOperations();
for(MBeanOperationInfo mBeanAttributeInfo : mBeanAttributeInfos){
System.out.println(mBeanAttributeInfo.getName());
}
long [] allThreadIds = (long [])RemoteConnector.getRemote().getAttribute(bean,"AllThreadIds");
Object [] params = new Object[2];
int maxDepth = 100;
params[0] = allThreadIds;
params[1] = maxDepth;
String [] opSigs = {allThreadIds.getClass().getName(),"I"};
RemoteConnector.getRemote().invoke(bean,"getThreadInfo",params,opSigs);
Note that getRemote() method returns a mbeanserverconnection 注意,getRemote()方法返回一个mbeanserverconnection
I can't invoke the method getThreadInfo() on stub. 我无法在存根上调用方法getThreadInfo()。 I am getting this message
我收到此消息
2016-05-05 00:17:37 ERROR ThreadDumpCreator:67 - Operation getThreadInfo exists but not with this signature: ([J, I)
Please help me resolve this issue :) 请帮助我解决这个问题:)
Below is the method i used to connect remote mbeanserver 下面是我用来连接远程mbeanserver的方法
public class RemoteConnector {
private static MBeanServerConnection remote = null;
private static JMXConnector connector = null;
public static void defaultConnector(){
try {
JMXServiceURL target = new JMXServiceURL
("service:jmx:rmi://localhost:11111/jndi/rmi://localhost:9999/jmxrmi");
//for passing credentials for password
Map<String, String[]> env = new HashMap<String, String[]>();
String[] credentials = {"admin", "admin"};
env.put(JMXConnector.CREDENTIALS, credentials);
connector = JMXConnectorFactory.connect(target, env);
remote = connector.getMBeanServerConnection();
}catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static MBeanServerConnection getRemote() {
return remote;
}
public static void setRemote(MBeanServerConnection remote) {
RemoteConnector.remote = remote;
}
public static void closeConnection() throws IOException {
if(connector != null){
connector.close();
}
}
} }
显然我应该使用int.class.getName()作为调用方法所要求的方法签名
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.