I have created a class to send messages to a JBoss queue. It works well but there is a lot of overhead with each send method call (roughly 60% from what I can tell) since each time I'm doing JNDI lookups of the QueueConnectionFactory and Queue, and then establishing the QueueConnection, QueueSession, and QueueSender. I'm thinking that if I convert the class to a stateless session EJB then I could persist the QueueConnection, QueueSession, and QueueSender as instance variables and avoid this overhead with each call. My idea is to perform the lookups and initializations in my ejbCreate() method, use the QueueSender and QueueSession instance variables to do the send and commit in my send method, and then close the connection and session in my ejbRemove() method. Is this the right way to go about this ? If so then are there any further considerations for a clustered application ?
I have done something similar, but I limited what I did in the ejbCreate to only the lookups and getting the QueueConnection. In other words, lookup the QueueConnectionFactory, lookup the Queue, call createQueueConnection on the QueueConnectionFactory. That eliminates the majority of the speed issues.
The main reason I didn't keep the session around was because I was concerned that keeping a session open for a long period of time could cause problems. I really don't know if that is true or not.