gpt4 book ai didi

java - 远程 JMX 连接和通知的问题

转载 作者:搜寻专家 更新时间:2023-11-01 03:56:00 26 4
gpt4 key购买 nike

我正在尝试遵循 Java API 文档 (http://download.oracle.com/javase/1.5.0/docs/api/java/lang/management/MemoryPoolMXBean.html#Notification) 中的一个相关示例内存池 Bean 和通知的 UsageThreshold 属性。我的意图是每次池超过阈值时都做一些事情。这是示例代码:

MemoryPoolMXBean remoteOldGenMemoryPool =
ManagementFactory.newPlatformMXBeanProxy(
jmxServer,
"java.lang:type=MemoryPool,name=PS Old Gen",
MemoryPoolMXBean.class);


class MyListener implements javax.management.NotificationListener {
public void handleNotification(Notification notification, Object handback) {
String notifType = notification.getType();
if (notifType.equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED)) {
// Do Something
println "Threshold passed";
}
}
}

// Register MyListener with MemoryMXBean
MemoryMXBean remoteMemory =
ManagementFactory.newPlatformMXBeanProxy(
jmxServer,
ManagementFactory.MEMORY_MXBEAN_NAME,
MemoryMXBean.class);

NotificationEmitter emitter = remoteMemory as NotificationEmitter;
MyListener listener = new MyListener();
emitter.addNotificationListener(listener, null, null);

remoteOldGenMemoryPool.setUsageThreshold 500000000;

当我执行代码并连接到我的 JVM 时,我可以看到以下内容:

Threshold passed
02-Feb-2011 16:30:00 ClientCommunicatorAdmin restart
WARNING: Failed to restart: java.io.IOException: Failed to get a RMI stub: javax.naming.CommunicationException [Root exception is java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is:
java.net.SocketException: Connection reset]
02-Feb-2011 16:30:03 RMIConnector RMIClientCommunicatorAdmin-doStop
WARNING: Failed to call the method close():java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is:
java.net.SocketException: Connection reset
02-Feb-2011 16:30:03 ClientCommunicatorAdmin Checker-run
WARNING: Failed to check connection: java.net.SocketException: Connection reset
02-Feb-2011 16:30:03 ClientCommunicatorAdmin Checker-run
WARNING: stopping

出于某种原因(我还不明白)代码正在尝试重新启动与 JVM 的连接。为什么会发生这种情况或如何防止这种情况的任何想法?我做错了什么吗?

谢谢

最佳答案

也许您可以向 jmx 环境添加一个变量,如下所示:m.put("jmx.remote.x.client.connection.check.period", 0L);

但是,我遇到的情况与此略有不同。你可以看到:http://chainhou.iteye.com/blog/1906688 .

关于java - 远程 JMX 连接和通知的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4877361/

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