gpt4 book ai didi

java - JMS 性能

转载 作者:IT老高 更新时间:2023-10-28 20:52:31 25 4
gpt4 key购买 nike

我在从性能角度理解 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);
}

代码是正确的,但可能上述一些人工制品可以重复用于多条消息。这些是我们的配置:

  • 我们使用 Oracle Weblogic 10.3.3
  • Weblogic 连接到用于 JMS 的 IBM MQ 7.0(6.0 也出现问题)
  • 上述逻辑由后端服务器上的单个线程执行。将一些对象(QueueConnectionQueueSessionQueueSender)保留在内存中会很简单,因为不涉及并发。

我的问题

  • 哪些类型的对象可以在多条消息之间共享? (当然我们会包括错误恢复、恢复那些共享对象)
  • 提高性能的最佳做法是什么?

最佳答案

这里是 jms spec 的一些相关部分:

第 2.8 节多线程

JMS Object          Supports Concurrent Use
Destination YES
ConnectionFactory YES
Connection YES
Session NO
MessageProducer NO
MessageConsumer NO

第 4.4.14 节客户端代码的串行执行

JMS does not cause concurrent execution of client code unless a client explicitly requests it. One way this is done is to define that a session serializes all asynchronous delivery of messages

所以如前所述,尽可能多地重用。为所有线程重用 ConnectionFactory、Connection 和 Destinations。为每个线程重用消费者和生产者。

如果您正在重用 JMS 连接,请注意,JMS 提供程序将在该连接上多路复用不同的 session 。因此,即使重用连接是安全的,为您需要的每个 session 创建一个连接可能会更快。

关于java - JMS 性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5470691/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com