Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the JMS QueueSender thread safe?

I want to use a QueueSender in a multi-threaded environment.

Is QueueSender.send() thread safe?

like image 795
mebada Avatar asked Feb 15 '10 14:02

mebada


People also ask

Is Activemqconnectionfactory thread safe?

As far as I know from the Java side, the connection is thread safe (and rather expensive to create) but Session and messageProducer are not thread safe. Therefore it seems you should create a Session for each of your threads.

Are Java variables thread safe?

Using Final keywordFinal Variables are also thread-safe in java because once assigned some reference of an object It cannot point to reference of another object.


1 Answers

No, a MessageProducer/QueueSender is not thread safe.

Or more specifically: The Session is not thread safe. The JavaDoc for Session explicitly mentions this in its first sentence:

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

And since a MessageProducer/QueueSender is bound to a Session you must not use it from more than one thread at the same time. In fact you must not use it from two different threads at different times either!

like image 59
Joachim Sauer Avatar answered Sep 19 '22 08:09

Joachim Sauer