users@glassfish.java.net

Re: JMS connection

From: <glassfish_at_javadesktop.org>
Date: Sat, 20 Jun 2009 15:31:23 PDT

The code was truncated (I sent it by email, and on the mailing list it appeared correctly, not on the forum).
This was the snippet (slightly enhanced):

[code]
public class FooBean implements FooRemote {

  @Resource(name="...", mappedName="...")
  public TopicConnectionFactory connectionFactory;
  @Resource(name = "..", mappedName = "...")
  private Topic topic;

  public void bar() {

    TopicConnection connection = null;
    TopicSession session = null;
    TopicPublisher publisher = null;

    try {
       connection = connectionFactory.createTopicConnection(); // Exception
       session = connection.createTopicSession(false, session.AUTO_ACKNOWLEDGE);
       publisher = session.createPublisher(topic);

       Message msg = session.createTextMessage("something");
       publisher.publish(msg);
    } catch (Throwable t) {
       // Exception handling here
       // ....
    } finally {

            if (publisher!=null)
                try { publisher.close(); } catch (Throwable t) {}
    
            if (session != null)
                try { session.close(); } catch (Throwable t) {}

            if (connection == null)
                try { connection.close(); } catch (Throwable t) {}
       }
    }
  }
}

[/code]

The connection.close() was there... On Monday I'm going to try what you suggested and let you know.
[Message sent by forum member 'danilo_levantesi' (danilo_levantesi)]

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