使用来自不同线程的JMS会话 [英] Using a JMS Session from different threads

查看:144
本文介绍了使用来自不同线程的JMS会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自会话的javadoc states:

From the javadoc for Session it states:


Session对象是用于生成和使用消息的单线程上下文。

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

所以我明白你不应该同时使用来自两个不同线程的Session对象。我不清楚的是,你是否可以使用与其创建的不同的线程中的Session对象(或者像Queue这样的子节点)。

So I understand that you shouldn't use a Session object from two different threads at the same time. What I'm unclear on is if you could use the Session object (or children such as a Queue) from a different thread than the one it created.

在这种情况下我正在研究,我正在考虑将我的Session对象放入一个可用会话池中,任何线程都可以借用,使用,并在完成后返回池中。

In the case I'm working on, I'm considering putting my Session objects into a pool of available sessions that any thread could borrow from, use, and return to the pool when it is finished with it.

这是犹太人吗?

(使用ActiveMQ BTW,如果这会影响答案。)

(Using ActiveMQ BTW, if that impacts the answer at all.)

推荐答案

我认为来自 JMS 1.1规范揭示了一些亮点:

I think the footnote from section 4.4 in the JMS 1.1 spec sheds some light:


没有限制可以使用Session对象或其创建的线程数。限制是多个线程不应同时使用会话的资源。用户应确保满足此并发限制。最简单的方法是使用一个线程。在异步传送的情况下,使用一个线程在停止模式下进行设置,然后启动异步传送。在更复杂的情况下,用户必须提供显式同步。

There are no restrictions on the number of threads that can use a Session object or those it creates. The restriction is that the resources of a Session should not be used concurrently by multiple threads. It is up to the user to insure that this concurrency restriction is met. The simplest way to do this is to use one thread. In the case of asynchronous delivery, use one thread for setup in stopped mode and then start asynchronous delivery. In more complex cases the user must provide explicit synchronization.

通过我阅读规范,你想要做的就是好的,只要你正确管理并发。

By my reading of the spec what you want to do is OK, provided you correctly manage concurrency.

这篇关于使用来自不同线程的JMS会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆