Search code examples
javajmx

Is holding a java JMX connection open a good idea


I have a support website that I would like to show some stats gathered from another Java app via JMX. We have noticed the support app sometimes cannot get the stats after the other app has been restarted. I guess this is because the support app has opening a JMX connection to the other app and keeps hold of it. Then every time you go to the page to display the JMX stats it tries to gather them using the connection and it fails.

My question is, is it better to have a single JMX connection and try and work out when we should reconnect it?

Or each time we load the page with JMX stats on it should we create a new JMX connection then close it once we have the values we need?


Solution

  • As per my knowledge,

    JMX connections are RMI Connector objects and hence can be held in the client app. + use a heartbeat approach to reconnect.

    This way we can avoid overhead of re-establishing RMI connections which are not light weight.

    Refer: javax.management.remote.rmi.RMIConnector