Java 远程JMX连接和通知出现问题
我试图遵循JavaAPI文档中的一个示例(http://download.oracle.com/javase/1.5.0/docs/api/java/lang/management/MemoryPoolMXBean.html#Notification)与内存池bean和通知的UsageThreshold属性相关。我的意图是,每当游泳池超过阈值时,都要做些什么。这是示例代码:Java 远程JMX连接和通知出现问题,java,groovy,notifications,jmx,mbeans,Java,Groovy,Notifications,Jmx,Mbeans,我试图遵循JavaAPI文档中的一个示例(http://download.oracle.com/javase/1.5.0/docs/api/java/lang/management/MemoryPoolMXBean.html#Notification)与内存池bean和通知的UsageThreshold属性相关。我的意图是,每当游泳池超过阈值时,都要做些什么。这是示例代码: MemoryPoolMXBean remoteOldGenMemoryPool = ManagementFacto
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) 但是,我所遇到的与此几乎没有什么不同。
您可以看到: 看起来这实际上是一个保持JMX连接活动的问题。ClientCommunicatorAdmin中有一个守护进程线程(Checher),它每分钟检查一次连接。