- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
在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/
我是一名优秀的程序员,十分优秀!