gpt4 book ai didi

javax.jms.MessageListener : What additional threading concerns to take care of?

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:29:26 24 4
gpt4 key购买 nike

this关于 JMS 的好文章,Bruce Snyder(“ActiveMQ in Action”的作者)提到:

[one] of the options for implementing a message listener to be used with the Spring DMLC is using javax.jms.MessageListener - It is a standardized interface from the JMS spec but handling threading is up to you.

另外两个选项Spring SessionAwareMessageListener和MessageListenerAdapter中他没有讲线程

我的问题是:与其他两种方法相比,使用普通的 javax.jms.MessageListener 需要解决哪些额外的线程问题?

我在想,无论我从以上 3 个选项中选择哪个选项,如果我的监听器将在多个线程上接收消息,我的监听器实现必须是线程安全的。

我查看了 Bruce 在 github 中创建的示例对于所有三个选项。在任何情况下,我都没有看到对线程的任何特定处理。simple 的 xml和 session-aware消费者几乎相同。

最佳答案

只要您不在MessageListener 实现中保留任何状态(通过实例变量),您就不必担心这三种方法中任何一种的线程安全性。如果您要保持状态,那么就像在任何多线程场景中一样,您必须注意如何同步对状态的访问。

关于javax.jms.MessageListener : What additional threading concerns to take care of?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16448951/

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