users@glassfish.java.net

Re: JMS Exception on Cluster

From: <forums_at_java.net>
Date: Tue, 30 Jul 2013 10:09:37 -0500 (CDT)

Here's your send method: public void send(QueueItem queueItem) {
logger.fine("Session object is created.."); Session session =
connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer
producer = session.createProducer(dest); logger.fine("Producer object is
created.."); ObjectMessage message = session.createObjectMessage();
message.setObject(queueItem); producer.send(message); } This method creates a
new session from the same connection. I don't see any code to close this
session (or the connection) after use. This means that the second time you
call this method you'll violate the Java EE restriction that says that an
application running in a Java EE web or EJB container may only create one
session per connection. In general, it's best to close the connection and
session after you've finished using it. Closing the connection will
automatically close the session. So the following should work: public void
send(QueueItem queueItem) { Connection connection =
connectionFactory.createConnection(); Session session =
connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer
producer = session.createProducer(dest); ObjectMessage message =
session.createObjectMessage(); message.setObject(queueItem);
producer.send(message); connection.close(); }

--
[Message sent by forum member 'nigeldeakin']
View Post: http://forums.java.net/node/898001