-
1. Re: When to release JMS resource in container-mamager transa
schrouf Feb 23, 2004 5:52 AM (in response to jieshengz)Just close() your JMS connection at the end of your method call. The container will internally commit your transaction ( therefore it's container managed transaction :-)
BTW: put all your connection/session.close() code into a finally block for avoiding memory leaks. Always catch exceptions and call ctx.setRollbackOnly() in such a case.
Connection rConnection = null;
try
{
// get resources
rConnection = ....
// do the work
.....
}
catch( Exception eEx )
{
// rollback transaction (will be handled by container)
ctx.setRollbackOnly();
}
finally
{
// close resources (will internally commit transaction
// if setRollbackOnly() has NOT been called )
if( rConnection != null ) try{ rConnection.close(); } catch( Exception eIgnore) {};
} -
2. Re: When to release JMS resource in container-mamager transa
adrian.brock Feb 23, 2004 6:44 AM (in response to jieshengz)You also need to close the session and sender.
Regards,
Adrian -
3. Re: When to release JMS resource in container-mamager transa
pepgrifell Feb 26, 2004 5:03 AM (in response to jieshengz)So, what happens if I don´t close the sender and the session but I close the connection ?
As Adrian says, after sending a message the right thing should be :finally { try{ if( sender != null ) sender.close(); if( session != null ) session.close(); if( connection != null ) connection.close(); } catch( Exception e) {}; }