Section J2EE.6.6: JMS 1.1 Requirements of the J2EE 1.4 specification states:
Application components in the web and EJB containers must not attempt to create more than one active (not closed) Session object per connection. ... Application client containers must support the creation of multiple
sessions for each connection.
This means that in a J2EE container (web or EJB), a Connection can only have one Session. The spec doesn't explain why this change has been made, but it has to do with the way JMS is now built on the J2EE Connector Architecture 1.5 (commonly though unofficially called "JCA") and the way its connection model works. In JMS, a Connection represents a connection to the messaging provider and a Session represents a transaction within a connection. In JCA, a Connection represents both a connection and a tranactional context. To make a JMS connection work like a JCA connection, it can only have one session.
As a practical matter, this won't make code less efficient because connections are pooled and reused by the container. But it does affect the way you write your code. (In a J2SE container, a JMS client still has the previous behavior of a JMS Connection being able to support multiple Sessions.)
This change in J2EE 1.4 means that when you port your J2EE 1.3 code (from WAS 5 to WAS 6, for example), you need to review the places in your code that create JMS sessions and make sure they only create one session per connection, or else the code will fail at runtime. It won't affect your MessageDrivenBean (MDB) code because the container creates the connections and sessions for MDBs (for example, in WAS, this is managed by a ListenerPort). Likewise, your J2EE code probably doesn't create MessageConsumers; it should use MDBs instead (unless you have an aversion to EJBs in general). But this change may well be a problem for your sender code.
What you need to search for is code creating MessageProducers (i.e. QueueSenders and TopicPublishers) that does something like this:
ConnectionFactory factory = /* get the factory from JNDI */
Destination toDestination = /* get the destination from JNDI */
Destination fromDestination = /* get the destination from JNDI */
Connection connection = factory.createConnection();
Session session1 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session1.createProducer(toDestination);
. . .
Session session2 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session2.createConsumer(fromDestination);
(For simplicity, this example shows JMS 1.1 code. Your JMS 1.0.2 code will use the corresponding Queue- or Topic-specific subtypes.)
The problem here is that connection is being used to create both session1 and session2. You will need to change this code for J2EE 1.4 to create two connections, then create a session for each. On the other hand, if you existing code creates a Connection and then uses it to create only one Session, that code will work fine in J2EE 1.4 as is.[Read More]