Can all the objects (messages, message consumers, durable subscribers, message producers, queue browsers, and temporary destinations ) associated with a session object be used across multiple threads?

Can all the objects (messages, message consumers, durable subscribers, message producers, queue browsers, and temporary destinations ) associated with a session object be used across multiple threads?

book

Article ID: KB0086566

calendar_today

Updated On:

Products Versions
TIBCO Enterprise Message Service -
Not Applicable -

Description

Resolution:
1. The following are excerpted from JMS specification:


JMS Object       Supports Concurrent Use
================================================
Destination                   YES
ConnectionFactory        YES
Connection                   YES
Session                       NO
MessageProducer         NO
MessageConsumer         NO
=================================================

Clients that desire concurrent delivery can use multiple sessions. In effect, each
session’s listener thread runs concurrently. While a listener on one session is
executing, a listener on another session may also be executing.

It is erroneous for a client to use a thread of control to attempt to
synchronously receive a message if there is already a client thread of control
waiting to receive a message in the same session.

If a client desires to have one thread producing messages while others
consume them, the client should use a separate session for its producing
thread.


2. The above information means all objects created by the same session (i.e. producers and
consumers) should be only used in a single thread, JMS does not provide safe
threaded access on same session. You should use multiple sessions for concurrent Use.

It does not mean only one physical thread can access all session related objects,
you can access them from many thread, but only one at a time.

With Tibco EMS:

-- For session, message and producer objects:

If your application may call the SAME object (i.e. send messages) from multiple
threads simultaneously, then you should synchronize access in your application,
i.e. guard calling tibjmsMsgProducer.Send() with a lock.

-- For message consumers and queue browsers:

You should not used them across the threads

Also, you may get the following exception, if you do so:

javax.jms.IllegalStateException("Can not set consumer listener when session has a listener");
javax.jms.IllegalStateException("Illegal to call receive when session listener is set");


-- For TemporaryQueue and TemporaryTopic object:

They act the same as normal topics and queues

-- The same concept applies to C and .NET API.

Issue/Introduction

Can all the objects (messages, message consumers, durable subscribers, message producers, queue browsers, and temporary destinations ) associated with a session object be used across multiple threads?