Obtaining a session

Once a connection is made, use the createQueueSession method on the QueueConnection to obtain a session.

The method takes two parameters:

  1. A boolean that determines whether the session is "transacted" or "non-transacted".
  2. A parameter that determines the "acknowledge" mode.

The simplest case is that of the "non-transacted" session with AUTO_ACKNOWLEDGE, as shown in the following code fragment:

QueueSession session;
 
boolean transacted = false;
session = connection.createQueueSession(transacted,
                                        Session.AUTO_ACKNOWLEDGE);
Note:
A connection is thread safe, but sessions (and objects that are created from them) are not. The recommended practice for multi-threaded applications is to use a separate session for each thread.


© IBM Corporation 1997, 2002. All Rights Reserved