I am trying to create a Java Application Client project that sends a JMS message to a queue on a Glassfish server.
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 static void main
, and that's where it hangs.
Here is the 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();
}
}
How can I make it stop hanging?