I am setting up a MessageListener and expect that the program will still run (since the listening thread is still alive), but after "Finished" is printed on the screen, the program is terminated. Any idea why this happens and how to fix it?

    MessageListener messageListener = new DelegationReceiver();
    Properties p = PropertiesLoader.getProperties("jms.properties");
    InitialContext cntxt = new InitialContext();

    cntxt.addToEnvironment(Context.INITIAL_CONTEXT_FACTORY, p.getProperty("namingFactory"));
    cntxt.addToEnvironment(Context.URL_PKG_PREFIXES, p.getProperty("urlPackages"));
    cntxt.addToEnvironment(Context.PROVIDER_URL,p.getProperty("providerURL"));
    cntxt.addToEnvironment(Context.SECURITY_PRINCIPAL,"default");
    cntxt.addToEnvironment(Context.SECURITY_CREDENTIALS,"password");
    ConnectionFactory tfact = (ConnectionFactory) cntxt.lookup(p.getProperty("topicFactory"));
    Topic topic = (Topic) cntxt.lookup(p.getProperty("myTopic"));
    Connection connection = tfact.createConnection();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer mc = session.createConsumer(topic);
    mc.setMessageListener(messageListener);
    connection.start();
    System.out.println("Finished");
0

There are 0 best solutions below