title: Sending message with JMS hangs on exit
body: <p>I am trying to create a Java Application Client project that sends a JMS message to a queue on a Glassfish server.</p>
  
  <p>The problem is that after the app sends the message, it hangs when it's supposed to exit. The message is transmitted successfully, but for some reason the app doesn't exit. I have tried to debug the application, and I can step trough it all the way to the end of <code>static void main</code>, and that's where it hangs.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>import javax.jms.*;
  import javax.naming.InitialContext;
  
  
  public class Main {
  
  public void SendMessage() throws Exception {
      InitialContext ctx = new InitialContext();
      ConnectionFactory cf = (ConnectionFactory) ctx.lookup("jms/TestFactory");
      Queue queue = (Queue)ctx.lookup("jms/TestQueue");
      Connection conn = cf.createConnection();
      Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      MessageProducer prod = s.createProducer(queue);
  
      TextMessage txt = s.createTextMessage("testing");
      prod.send(txt);
  
      prod.close();
      s.close();
      conn.close();
  }
  
  public static void main(String[] args) throws Exception {
      Main m = new Main();
      m.SendMessage();
  }
  
  public Main() {
      super();
  }
  
  }
  </code></pre>
  
  <p>How can I make it stop hanging?</p>