jQuery in Action, 2nd edition*
The moose likes EJB and other Java EE Technologies and the fly likes how to close connection to activemq Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "how to close connection to activemq" Watch "how to close connection to activemq" New topic
Author

how to close connection to activemq

Andrew Cane
Ranch Hand

Joined: Aug 07, 2013
Posts: 91

I wish to know if there's anything else I need to do in the "cleaning up the mess" section. thank you
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10240
    
168

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.

[My Blog] [JavaRanch Journal]
Andrew Cane
Ranch Hand

Joined: Aug 07, 2013
Posts: 91
Yup, I know. This is just an initial test to establish connection to activemq. Do I need to deallocate mBroker object or any other object? thanks
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10240
    
168

Do I need to deallocate mBroker object


Those are just MBeans which typically don't hold on to a open resource, so you don't need any close call on those.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19723
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Andrew Cane
Ranch Hand

Joined: Aug 07, 2013
Posts: 91
okay, thanks a lot guys.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10240
    
168

Rob Spoor wrote:
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.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19723
    
  20

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...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to close connection to activemq