Jaikiran Pai wrote:That looks fine, except of course it should be done in a finally block or if you are using Java 7, then use the try-with-resources feature to auto close it.
Only if JMXConnector implements AutoCloseable. javax.jms.Connection (and all other JMS interfaces) don't in JEE6; in JEE7 this is corrected but it's not always possible to upgrade.
Actually, given that this is client side code, if it's using Java 7 then that's should be enough since the JMXConnector comes bundled in the standard JRE. But yes, javax.jms.* is a different story since those classes aren't part of standard JRE.
Well, JMXConnector does implement AutoCloseable indirectly, since it implements Closeable. I wasn't aware that it was part of JSE though. All I know is that JEE6 doesn't have support for AutoCloseable. Strangely enough, in JEE7 most of JMS does but just about all other existing classes / interfaces (like those of JavaMail) still don't...