从性能角度理解JMS我遇到了一些麻烦.我们在应用程序中有这么简单的代码:
QueueConnection connection = null;
QueueSession session = null;
QueueSender sender = null;
TextMessage msg = null;
try {
// The JNDIHelper uses InitialContext to look up things
QueueConnectionFactory qcf = JNDIHelper.lookupFactory();
Queue destQueue = JNDIHelper.lookupQueue();
// These objects are created for every message, which is quite slow
connection = qcf.createQueueConnection();
session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
sender = session.createSender(destQueue);
// This is the actual message
msg = session.createTextMessage(xmlMsg);
sender.setTimeToLive(0);
sender.send(msg);
}
finally {
// Close all objects again
JMSUtilities.safeClose(sender);
JMSUtilities.safeClose(session);
JMSUtilities.safeClose(connection); …Run Code Online (Sandbox Code Playgroud) 我们有一个JMS队列,它接收大量的消息.
监听器必须使用数据库事务在数据库中保存消息,然后提交JMS事务.
那么我怎么能更有效地做到这一点,我不必在每条消息上做数据库和JMS提交.