开发者

JMS application client can create more than one active sessions while web/ejb components cannot?

I am reading the JEE5 tutorial for JMS.

And I am having a hard time understanding the reason for this 'general rule':

A general rule in the Java EE platform specification applies to all Java EE components that use the JMS API 开发者_JAVA技巧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.

Why does it not apply to the application clients and applies to the web/EJB components.?


There are quite a number of rules concerning JMS that are different when using it from a standalone client and from within a Java EE environment. One thing that comes to mind is the ability to create a JMS Listener.

And old (but still relevant quote from the 1.3 spec):

... 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. ....

I guess that it's not allowed to create multiple sessions per connection in a Java EE environment since those connections are managed, and it's difficult to keep them apart this way. But hopefully someone can give a more definite answer.

Note that the new 2.0 version of JMS for Java EE 7 has a better and more clear alignment between the core JMS spec and Java EE as one of its goals. See here: http://jcp.org/en/jsr/detail?id=343

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜