gpt4 book ai didi

java - 以编程方式创建远程 jvm 的线程转储

转载 作者:行者123 更新时间:2023-12-01 09:57:56 24 4
gpt4 key购买 nike

我一直在尝试在远程 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

我无法在 stub 上调用 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();
}
}

}

最佳答案

显然我应该使用 int.class.getName() 作为调用方法所需的方法签名

关于java - 以编程方式创建远程 jvm 的线程转储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37035917/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com