Create 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:
- A parameter that specifies whether the session is transacted or not transacted
- 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.
- Transacted sessions in JMS applications
JMS applications can run local transactions by first creating a transacted session. An application can commit or roll back a transaction.- Acknowledgment modes of JMS sessions
Every session that is not transacted has an acknowledgment mode that determines how messages received by the application are acknowledged. Three acknowledgment modes are available, and the choice of acknowledgment mode affects the design of the application.Parent topic: Writing IBM MQ classes for JMS applications