Reputation: 365
If yes, which moment we need to call JMXConnector.close() method?
public class MyClass
{
public static JMXConnector jmxc = . . .
public static MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
.........
public logSomeJmxStats()
{
mbsc.invoke(.....)
}
public updateSomeJmxStats()
{
mbsc.invoke(.....)
}
}
This Java class is used by Java application running as a service.
Upvotes: 1
Views: 527
Reputation: 13546
This is from the documentation of JMXConnector.getMBeanServerConnection:
For a given JMXConnector and Subject, two successful calls to this method will usually return the same MBeanServerConnection object, though this is not required.
So I would think that you safely may reuse it. Though you may be safer by not reusing it.
You should call close if noone is going tho use the connection again. This may be easier to achieve if you don't put the connection in a static field but an instance field. So when you shutdown your application you can hook onto that an close the connection.
Upvotes: 1