保持 JMS 连接/ session /消费者始终打开是一种不好的做法吗?
代码草稿示例:
// 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();
有什么改进 JMS 使用模式的建议吗?
最佳答案
同意。这里有一些 good tips on how to use JMS efficiently其中包括保持连接/ session /生产者/消费者。
您可能还想查看 recommendation on using transactions如果您对最大化性能感兴趣,也是如此。
关于java - 长期存在的 JMS session 。保持 JMS 连接/JMS session 总是打开不好的做法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/274051/