Is it okay to keep an MBeanServerConnection alive
I'm writing a monitoring application which constantly monitors the performance of a certain application. I get the performance numbers by invoking some methods through JMX every 5 min. Should I open up a MBeanServerConnection and use that connection object all the time for invoking the method, without ever closing it? Or should I reconnect every 5 minutes? What is the best practice in this case?
Thanks a lot in advance.
[438 byte] By [
Joannea] at [2007-11-26 16:38:34]

# 1
Hi Joanne,
Yes, this is perfectly OK, and I would even recommend to do so.
Opening a new connection would be more costly - especially if it's secured.
The JMX connector may transparently close and reopen the connection behind
the scene if it is not being used.
If you have only one connection (or only a few connections) I would suggest that
you open your connection when you start your monitoring
application, and close it only at the end when you stop the application and no
longer need it.
If however you are monitoring a large number of agents from the same client
JVM, you may want to reconsider your decision - since having a large number
of connections opened and alive in parallel in that client JVM may lead to
scalability issues on the client side.
Hope this helps.
-- daniel
JMX, SNMP, Java, etc...
http://blogs.sun.com/jmxetc