jakarta-ee - JMS 应用程序客户端可以创建多个事件 session 而 web/ejb 组件不能吗?

标签 jakarta-ee jms ejb java-ee-5

我正在阅读 JEE5 tutorial for JMS .

我很难理解这个“一般规则”的原因:

A general rule in the Java EE platform specification applies to all Java EE components that use the JMS API within EJB or web containers:

Application components in the web and EJB containers must not attempt to create more than one active (not closed) Session object per connection.

This rule does not apply to application clients.

为什么它不适用于应用程序客户端而适用于 web/EJB 组件?

最佳答案

在独立客户端和 Java EE 环境中使用 JMS 时,有很多不同的规则。我想到的一件事是创建 JMS 监听器的能力。

旧的(但仍然与 1.3 规范相关的引用):

... Note that the JMS API creates threads to deliver messages to 
message listeners. The use of this message listener facility may be 
limited by the restrictions on the use of threads in various 
containers. In EJB containers, for instance, it is typically not 
possible to create threads. The following methods must not be used by 
application components executing in containers that prevent them 
from creating threads: 
. 
- javax.jms.Session method setMessageListener 
- javax.jms.Session method getMessageListener 
- javax.jms.Session method run 
- javax.jms.QueueConnection method createConnectionConsumer 
- javax.jms.TopicConnection method createConnectionConsumer 
- javax.jms.TopicConnection method createDurableConnectionConsumer 
- javax.jms.MessageConsumer method getMessageListener 
- javax.jms.MessageConsumer method setMessageListener 
. 
In addition, use of the following methods on javax.jms.Connection
objects by applications in Web and EJB containers may interfere with the
connection management functions of the container and must not be used:
- setExceptionListener 
- stop
- setClientID 
A J2EE container may throw a JMSException if the application component 
violates these restrictions. ....

我猜想在 Java EE 环境中不允许为每个连接创建多个 session ,因为这些连接是受管理的,并且很难以这种方式将它们分开。但希望有人能给出更明确的答案。

请注意,用于 Java EE 7 的新 2.0 版 JMS 将核心 JMS 规范和 Java EE 之间更好、更明确的一致性作为其目标之一。看这里:http://jcp.org/en/jsr/detail?id=343

关于jakarta-ee - JMS 应用程序客户端可以创建多个事件 session 而 web/ejb 组件不能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5657580/

相关文章:

java - JMS 消费者阻止其他 JMSXGroups

java - 从 jboss 5 迁移到 7

java - ejb 3.1定时器服务如何计算超时?

java - Spring 安全http 404错误

java - 使用 hibernate 在 JPA 中配置 EntityManager

java - Hibernate & EhCache : net. sf.ehcache.Statistics 未填充?

java - 使用以下几个队列进行请求-回复

java - Spring -JMS-数据库

java - 如何强制TopLink立即建立OneToMany关系?

java - JAX-RS 资源作为 POJO 与 CDI 与 EJB