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
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();
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(
// create session
Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
// create TopicSubscriber
TopicSubscriber subscriber = session.createDurableSubscriber(topic, subscriberName);
// start connection
Here are the steps I use when shutting everything down:
Upon profiling and debugging, these threads are still running immediately upon closing the JNDI Context:
After roughly 30 seconds, all but the following threads terminate:
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.