Obtaining a session

 

After a connection is made, use the createSession() method on the Connection object to obtain a session. The method has two parameters:

  1. A boolean parameter that determines whether the session is transacted or non-transacted.

  2. A parameter that determines the acknowledge mode.

The simplest case is obtaining a non-transacted session with an acknowledge mode of AUTO_ACKNOWLEDGE, as shown in the following code:

Session session;
.
.
.
boolean transacted = false;
session = connection.createSession(transacted, Session.AUTO_ACKNOWLEDGE);

A connection is thread safe, but sessions (and the objects that are created from them) are not. The recommended practice for multithreaded applications is to use a separate session for each thread.


uj25060_