aspose file tools*
The moose likes Threads and Synchronization and the fly likes Threads and JMS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Threads and JMS" Watch "Threads and JMS" New topic
Author

Threads and JMS

Dennis M Kavanagh
Greenhorn

Joined: Mar 26, 2007
Posts: 6
Hello,

1. Does anybody know if a Java Application running in an explicitly kicked-off Thread will accept a JMS Client string?

2. If so, are there any limitations on the message received by the client or the subsequent acknowledgements?

3. Does it make any difference to the Java Application running in a thread, if the JMS Client, Connection and Session are declared in the Threaded code or should the Connection be declared outside of the Thread with only the Session declared in the Thread?

4. Is the receipt of the JMS message considered an "atomic" opertion in a Java Threaded environment?

Thank You
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

I may be off base about your question but here goes an attempt to answer the question:

First, according to the JMS Specification JMS Objects Connection and ConnectionFactory are safe to use in a multi-threaded environment, but Session, MessageProducer, and MessageConsumer are not.

Here is what it means:
You can generate a Connection and share it between multiple Threads, and expect it to work fine.

You can generate a Session in a Thread, and expect it to work as normal.

A Session should be be limited to a single Thread. Multiple Threads accessing the same Session can cause several erroneous behaviors, and when multiple asynchronous consumers are added to the same session properly, they are dispatched to serially (not in parallel).

If you want multiple consumers running in parallel (in different Threads) you should use multiple Sessions - one for each Thread.

Since Sessions and MessageConsumers are not considered safe for multi-threading, I would assume that Message Receipt was not atomic. But I didn't find that specifically stated.


Steve
Dennis M Kavanagh
Greenhorn

Joined: Mar 26, 2007
Posts: 6
Thank You.....

Can I ask also if you have any experience with OpenJMS?
I am wondering whether or not it is still a viable technology to
select as a JMS Implementation Provider?

Thanks again
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

Sorry, I don't have experience with OpenJMS (or really any JMS implementation). Any knowledge I have is from reading specs.
 
 
subject: Threads and JMS