This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes Does access to a messaging queue need synchronization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Does access to a messaging queue need synchronization" Watch "Does access to a messaging queue need synchronization" New topic
Author

Does access to a messaging queue need synchronization

Ranadhir Nag
Ranch Hand

Joined: Mar 09, 2006
Posts: 138
This is seemingly an elementary question.
If we create a MQ or JMS queue connection - does it need synchronization for multiple threads to be able to send message to it?

MQEnvironment.hostname = hostname;
MQEnvironment.channel = channel;
MQEnvironment.port = portNumber;
qMgr = new MQQueueManager(qManager);
openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;
Queue = qMgr.accessQueue(outQueue,openOptions, null, null, null);

Can this 'Queue' handle be passed over to multiple threads to send over messages without synchronization?
If not, why?

Answers with proper justifications will be really appreciated.
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1756
    
    7

Thread safety guarentees, or lack thereof, are usually part of the JavaDoc API documentation of such frameworks. At least that's how it should be.

For instance, if you browse the API documentation for the IBM MQ classes for Java you'll find:

An MQQueueManager object (and any queues or processes accessed through it) can be shared between multiple threads, but be aware that access to the WebSphere MQ queue manager itself is synchronized, so that only one thread can communicate with it at any one time.


Similarly for JMS in its API documentation:

A Session object is a single-threaded context for producing and consuming messages.


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
 
 
subject: Does access to a messaging queue need synchronization
 
Similar Threads
thread doubt
HashMap or HashTable
MultiThreading and sockets
problem in reading message for IBM MQ series using IBM MQ classes
parameter in threads