users@glassfish.java.net

When to create a javax.jms.Connection

From: <glassfish_at_javadesktop.org>
Date: Fri, 21 Aug 2009 13:53:54 PDT

I have a Stateless Session bean that is responsible for sending messages onto a queue. It has a reference to a ConnectionFactory:
        
    @Resource(mappedName="jms/myConnectionFactory")
    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..
[Message sent by forum member 'cmathrusse' (cmathrusse)]

http://forums.java.net/jive/thread.jspa?messageID=361708