Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Is javax.jms.Session threadsafe?  RSS feed

 
Taariq San
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Javadoc says "A Session object is a single-threaded context for producing and consuming messages."

This doesn't say that its threadsafe or not threadsafe.

I have a reference to a QueueSession
which is used to create many senders to various queues.
To send a message each time I use that reference to create an ObjectMessage.

I only close this Session on finalize.

Any thoughts?
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JMS1.1 Specs, section 2.8 says that Session are not suitable to be used by concurrent threads. Following is the reason (as quoted from the spec)

There are two reasons for restricting concurrent access to Sessions. First,
Sessions are the JMS entity that supports transactions. It is very difficult to
implement transactions that are multithreaded. Second, Sessions support
asynchronous message consumption. It is important that JMS not require that
client code used for asynchronous message consumption be capable of
handling multiple, concurrent messages. In addition, if a Session has been set
up with multiple, asynchronous consumers, it is important that the client is not
forced to handle the case where these separate consumers are concurrently
executing. These restrictions make JMS easier to use for typical clients. More
sophisticated clients can get the concurrency they desire by using multiple
sessions.
 
Taariq San
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Nitesh.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!