I want to use a QueueSender in a multi-threaded environment.
Is QueueSender.send()
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.
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.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With