JMS Session objects have never been thread safe. You can use them however
you want as long as you guarantee thread safety. That said, thread safety
is notoriously difficult to implement & debug and Sessions are considered
"lightweight" objects so there's not much cost to creating a Session for
every producer. Relatively speaking you'll see better throughput with a
session-per-producer since you'll be leveraging concurrency, although
that's unlikely to have a statistically significant impact on your
application's overall performance. You'll have to weigh that against the
code complexity (and potential future bugs) of implementing your own thread
safety.

The javax.jms.Session JavaDoc [1] has a few worthwhile bits about threading.


Justin

[1] https://docs.oracle.com/javaee/7/api/javax/jms/Session.html

On Wed, Dec 21, 2022 at 1:02 PM John Lilley
<john.lil...@redpointglobal.com.invalid> wrote:

> Greetings!
>
>
>
> I have noticed that I cannot share a session between threads, at least not
> when using the JMS API.  Because of that, we are creating a new session for
> every producer.
>
> But is that necessary?  Can I share that session between all of my
> producers so long as there is no simultaneous use?  I can arrange to
> lock(session){} when messages are sent.
>
> And would reducing the number of sessions save any noticeable amount of
> resource (time, or broker memory?).  We tend to have about 20 producers per
> process.
>
>
>
> Thanks
>
> John
>
>
>
> [image: rg] <https://www.redpointglobal.com/>
>
> John Lilley
>
> Data Management Chief Architect, Redpoint Global Inc.
>
> 888 Worcester Street, Suite 200 Wellesley, MA 02482
>
> *M: *+1 7209385761 <+1%207209385761> | john.lil...@redpointglobal.com
>
> PLEASE NOTE: This e-mail from Redpoint Global Inc. (“Redpoint”) is
> confidential and is intended solely for the use of the individual(s) to
> whom it is addressed. If you believe you received this e-mail in error,
> please notify the sender immediately, delete the e-mail from your computer
> and do not copy, print or disclose it to anyone else. If you properly
> received this e-mail as a customer, partner or vendor of Redpoint, you
> should maintain its contents in confidence subject to the terms and
> conditions of your agreement(s) with Redpoint.
>

Reply via email to