简体   繁体   English

JMS QueueSender线程安全吗?

[英]Is the JMS QueueSender thread safe?

I want to use a QueueSender in a multi-threaded environment. 我想在多线程环境中使用QueueSender。

Is QueueSender.send() thread safe? QueueSender.send()线程安全吗?

No, a MessageProducer / QueueSender is not thread safe. 不, MessageProducer / QueueSender不是线程安全的。

Or more specifically: The Session is not thread safe. 或者更具体地说: Session不是线程安全的。 The JavaDoc for Session explicitly mentions this in its first sentence: JavaDoc for Session在第一句中明确提到了这一点:

A Session object is a single-threaded context for producing and consuming messages. Session对象是用于生成和使用消息的单线程上下文。

And since a MessageProducer / QueueSender is bound to a Session you must not use it from more than one thread at the same time. 由于MessageProducer / QueueSender绑定到Session您不能同时在多个线程中使用它。 In fact you must not use it from two different threads at different times either! 实际上你不能在不同时间从两个不同的线程中使用它!

Following screenshot is from JMS2 specs 以下截图来自JMS2规范

在此输入图像描述

As you can see Session Object does not support usage by concurrent threads. 如您所见,Session Object不支持并发线程的使用。 Session is not a thread safe Object. Session不是线程安全的Object。 Same gos for all Objects created from that Session instance like Messages,Producers,Consumers . 从该Session实例创建的所有对象的相同gos,如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. 因此,这些对象不能由两个线程共享,这是客户端应该关注的而不是JMS提供者。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM