Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MQ right way to close connection

I saw lots of examples like http://hursleyonwmq.wordpress.com/2007/05/29/simplest-sample-applications-using-websphere-mq-jms/, even on IBM publib. As I guess this code had a flaw: Queue connection closed in main block, and not in finally as I expected.

What is the right way to close MQ connection without leaks?

like image 203
coms Avatar asked Feb 02 '26 13:02

coms


1 Answers

I think it is better to do it in finally. i.e.

finally
{
   try
   {
      session.close();
   }
   catch (Exception ex)
   {
      System.err.println("session.close() : " + ex.getLocalizedMessage());
   }

   try
   {
      connection.close();
   }
   catch (Exception ex)
   {
      System.err.println("connection.close() : " + ex.getLocalizedMessage());
   }
}
like image 139
Roger Avatar answered Feb 05 '26 03:02

Roger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!