远程 JMX 连接和通知问题
我正在尝试遵循与UsageThreshold相关的Java API文档(http://download.oracle.com/javase/1.5.0/docs/api/java/lang/management/MemoryPoolMXBean.html#Notification)中的一个示例内存池 Bean 的属性和通知。我的目的是每当池子克服阈值时就做一些事情。这是示例代码:
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 的连接。任何想法为什么会发生这种情况或如何防止它?我做错了什么吗?
谢谢
I'm trying to follow one example from the Java API documentation (http://download.oracle.com/javase/1.5.0/docs/api/java/lang/management/MemoryPoolMXBean.html#Notification) related to the UsageThreshold property of the Memory Pool Beans and notifications. My intention is to do something every time the pool overcomes the threshold. This is the sample code:
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;
When I execute the code and connect to my JVM I can see the following:
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
For some reason (that I don't understand yet) the code is trying to restart the connection to JVM. Any ideas why this can be happening or how to prevent it? Am I doing somehing wrong?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许您可以向 jmx 环境添加一个变量,如下所示:
m.put("jmx.remote.x.client.connection.check.period", 0L);
但是,我遇到的情况与此略有不同。
你可以看到:http://chainhou.iteye.com/blog/1906688。
May be you can add a variable to the jmx enviroment, like this:
m.put("jmx.remote.x.client.connection.check.period", 0L);
But, what i have encountered is little different from this.
you can see : http://chainhou.iteye.com/blog/1906688.