+

Search Tips | Advanced Search

Creating a session in a JMS application

To create a session, a JMS application uses the createSession() method of a Connection object.

The createSession() method has two parameters:
  1. A parameter that specifies whether the session is transacted or not transacted
  2. A parameter that specifies the acknowledgment mode for the session
For example, the following code creates a session that is not transacted and has an acknowledgment mode of AUTO_ACKNOWLEDGE:
Session session;
.
boolean transacted = false;
session = connection.createSession(transacted, Session.AUTO_ACKNOWLEDGE);

When a JMS session is created, the IBM MQ classes for JMS creates a connection handle (Hconn) and starts a conversation with the queue manager.

A Session object, and any MessageProducer or MessageConsumer object created from it, cannot be used concurrently by different threads of a multithreaded application. The simplest way of ensuring that these objects are not used concurrently is to create a separate Session object for each thread.