As per this IBM technote it appears that since WAS 6 you're supposed to open and close the connection on a per-MQ-session basis. Because, when you close a session, the underlying connection responsible for creating the MQ session is implicitly returned to the pool.
Technote (troubleshooting)
Problem(Abstract)
You access WebSphere MQ V6.0 queues using JMS from a Java™ application which sits in EJB beans in WebSphere Application Server. The application has been running for a number of years with no errors, in WebSphere Application Server V5. You are now trying to run exactly the same Java application on WebSphere Application Server V6.
...
The relevant section of the failing method stack from the ffdc log shows:
javax.jms.IllegalStateException: Connection closed at com.ibm.ejs.jms.JMSConnectionHandle.checkOpen(JMSConnectionHandle.java:671) at com.ibm.ejs.jms.JMSQueueConnectionHandle.createQueueSession(JMSQueueConnectionHandle.java:172) ...
...
Cause
When the
genericPut
method completes, then a connection handle which was retrieved from the pool is dissociated from the application and returned to the JMS connection pool ......
Resolving the problem
Modify the application to create a new JMS connection every time the EJB is called. This is the recommended solution.
This will not have too much impact on performance, due to the way the application server's connection pooling mechanism works.
...
So, in your particular case, the proper approach would be as follows. Think of try-finally
like as in JDBC! You only don't need to explicitly close the session/sender as they are already implicitly closed on close of a connection:
public void sendMessage() throws JMSException {
QueueConnection connection = null;
try {
connection = connectionFactory.createQueueConnection();
QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
QueueSender sender = session.createSender(requestQueue);
TextMessage message = session.createTextMessage(text);
sender.send(message);
} finally {
if (connection != null) try {
connection.close();
} catch (JMSException e) {
// Log or ignore.
}
}
}