1 Reply Latest reply on Mar 4, 2014 12:27 PM by Justin Bertram

    Proper way to shut down client

    Jay Hutfles Newbie

      Hi everyone,

       

      I have a problem trying to shut down a JMS client, and was hoping to get some advice.  The destination is a topic running in JBoss (tried both AS 7.1.1.Final and EAP 6.1) with HornetQ as the JMS provider (versions 2.2.13.Final and 2.3.1.Final respectively).  It's defined simply as

       

        <jms-topic name="MyTopic">

          <entry name="topic/MyTopic"/>

          <entry name="java:jboss/exported/jms/topic/MyTopic"/>

        </jms-topic>

       

       

      The client is a J2SE app, in which I try to create a durable subscriber.  It connects fine, and sends/receives messages as expected.  But when shutting down, the client has daemon threads which don't stop, and the jvm process never terminates.

       

      Here are the steps I used for instantiating everything:

       

      // create jndiContext for looking up remote resources

      envProps = new Properties();

      envProps.load(new FileInputStream("src/main/resources/META-INF/jndi.properties"));

      jndiContext = new InitialContext(envProps);

       

      // create connection factory

      ConnectionFactory cf = (ConnectionFactory) jndiContext.lookup("jms/RemoteConnectionFactory");

       

      // lookup topic

      Topic topic = (Topic) jndiContext.lookup("jms/topic/MyTopic");

       

      // create connection

      Connection connection = cf.createConnection(

        envProps.getProperty("java.naming.security.principal"),

        envProps.getProperty("java.naming.security.credentials"));

      connection.setClientID("test");

       

      // create session

      Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);

       

      // create TopicSubscriber

      TopicSubscriber subscriber = session.createDurableSubscriber(topic, subscriberName);

       

      // start connection

      connection.start();

       

       

      Here are the steps I use when shutting everything down:

       

      subscriber.close();

      session.unsubscribe("testSubscriber");

      session.close();

      connection.stop();

      connection.close();

      jndiContext.close();

       

      Upon profiling and debugging, these threads are still running immediately upon closing the JNDI Context:

       

      immediately.jpg

       

      After roughly 30 seconds, all but the following threads terminate:

       

      eventually.jpg

       

      At this point, these threads stay alive indefinitely, and I have to kill the jvm process.

       

      I realize a lot of the stop() and close() methods may be redundant, but at this point I'm simply trying to terminate any loose ends at all.  Is there anything I'm doing which seems off?

       

      Thanks in advance for any advice.