title: How can I get this external JMS client to terminate?
body: <p>I'm working through the <a href="http://java.sun.com/products/jms/tutorial/1_3_1-fcs/doc/client.html#1056518" rel="nofollow noreferrer">'Simple Point-to-Point Example'</a> section of the Sun JMS tutorial (<a href="http://java.sun.com/products/jms/tutorial/1_3_1-fcs/examples/simple/SimpleQueueSender.java" rel="nofollow noreferrer">sender source</a>, <a href="http://java.sun.com/products/jms/tutorial/1_3_1-fcs/examples/simple/SimpleQueueReceiver.java" rel="nofollow noreferrer">receiver source</a>), using Glassfish as my JMS provider.  I've set up the QueueConnectionFactory and Queue in the Glassfish admin UI, and added the relevant JARs to my classpath and the receiver is receiving the messages sent by the sender.</p>
  
  <p>However, neither sender nor receiver terminate.  The main thread exits normally (after successfully calling <code>queueConnection.close()</code>) but two non-daemon threads are left hanging around:</p>
  
  <ul>
  <li>iMQReadChannel-0</li>
  <li>imqConnectionFlowControl-0</li>
  </ul>
  
  <p>It seems (from <a href="http://www.nabble.com/Simple-JMS-Client-doesn%27t-quit-td15662753.html" rel="nofollow noreferrer">this java.net thread</a>) that the reason is that <code>queueConnection.close()</code> just returns the connection to the pool, rather than really closing it.  I can't find any way to tell the pool to shutdown, so the only option I'm left with is <code>System.exit()</code>, which feels wrong.</p>
  
  <p>I've tried setting the minimum pool size to 0, the maximum pool size to 1 and the idle timeout to 10 seconds but it seems to make no difference.  Even when I just lookup the connection factory and don't ask for a connection, these two threads are still started and don't terminate.</p>
  
  <p>Any help much appreciated!</p>