Is keeping JMS connections / sessions / consumer always open a bad practice?
Code draft example:
// app startup code
ConnectionFactory cf = (ConnectionFactory)jndiContext.lookup(CF_JNDI_NAME); Connection connection = cf.createConnection(user,pass); Session session = connection.createSession(true,Session.TRANSACTIONAL); MessageConsumer consumer = session.createConsumer(new Queue(queueName)); consumer.setMessageListener(new MyListener()); connection.start(); connection.setExceptionListener(new MyExceptionHandler()); // handle connection error
// ... Message are processed on MyListener asynchronously ...
// app shutdown code
consumer.close(); session.close(); connection.close();
Any suggestions to improve this pattern of JMS usage?
Thanks.