我一直在尝试在远程jvm中调用ThreadMXBean上的操作。我使用的代码片段调用操作在
下面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);
请注意,getRemote()方法返回mbeanserverconnection
我无法在存根上调用方法getThreadInfo()。我收到此消息
2016-05-05 00:17:37 ERROR ThreadDumpCreator:67 - Operation getThreadInfo exists but not with this signature: ([J, I)
请帮我解决此问题:)
以下是我用来连接远程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();
}
}
}
答案 0 :(得分:1)
显然我应该使用int.class.getName(),因为方法签名需要来自invoke方法