Problem with JMX remote connection and notifications

I am trying to run one example from the Java API documentation (http://download.oracle.com/javase/1.5.0/docs/api/java/lang/management/MemoryPoolMXBean.html#Notification) on the Beans memory pool's UsageThreshold property and notifications. I intend to do something every time the pool breaks the threshold. This is a 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 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 (I don't understand yet) the code is trying to restart the connection to the JVM. Any ideas why this might happen or how to prevent it? Am I doing something wrong?

thank

+3
source share
1 answer

, jmx, : m.put( "jmx.remote.x.client.connection.check.period", 0L);

, , . : http://chainhou.iteye.com/blog/1906688.

0

Source: https://habr.com/ru/post/1789551/


All Articles