When to create a javax.jms.Connection
I have a Stateless Session bean that is responsible for sending messages onto a queue. It has a reference to a ConnectionFactory:
private javax.jms.ConnectionFactory connectionFactory;
I know the connectionFactory is defined as a ConnectionPool in the container so I am very accustomed to simply asking the factory for a connection. But I am leery as to holding onto the connection. Currently, each time a message is requested to be sent I create a new Connection, which is used to create a Session. After the send is complete I close both the Session and the Connection. But now I am wondering if it would be cleaner if I were to simply get the Connection once and hold onto it for the life of the bean rather than allocating a new Connection for each request.
Of course, all of the work is performed within a CMT. So should I simply ask for a Connection once and use it for all requests and simply deal with creating a Session for each request?
Thanks for the help..