Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to close connection to activemq

 
Andrew Cane
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Andrew Cane
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20669
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Andrew Cane
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay, thanks a lot guys.
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20669
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic