Is the JMS QueueSender thread safe?

五迷三道 提交于 2019-12-12 08:19:51

问题


I want to use a QueueSender in a multi-threaded environment.

Is QueueSender.send() thread safe?


回答1:


No, a MessageProducer/QueueSender is not thread safe.

Or more specifically: The Session is not thread safe. The JavaDoc for Session explicitly mentions this in its first sentence:

A Session object is a single-threaded context for producing and consuming messages.

And since a MessageProducer/QueueSender is bound to a Session you must not use it from more than one thread at the same time. In fact you must not use it from two different threads at different times either!




回答2:


Following screenshot is from JMS2 specs

As you can see Session Object does not support usage by concurrent threads. Session is not a thread safe Object. Same gos for all Objects created from that Session instance like Messages,Producers,Consumers. So these objects must not be shared by two threads and this is something client should take care of instead of JMS providers.



来源:https://stackoverflow.com/questions/2266461/is-the-jms-queuesender-thread-safe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!