icatproject / icat.server

The ICAT server offering both SOAP and "RESTlike" interfaces to a metadata catalog.
Other
1 stars 5 forks source link

try-with-resource JMS Session to send messages. Fixes #202 - again! #210

Closed stuartpullinger closed 5 years ago

stuartpullinger commented 5 years ago

In Transmitter.java, moves the creation of the Session to a try-with-resource statement – so the Session is recreated with each call to processMessage and will be closed properly if any exception is thrown.

RKrahl commented 5 years ago

As already I wrote in the issue discussion, I have only little knowledge about JMS. The source that you cite about the JMS connections and sessions being implicitly reused is from JBoss. But it states that this is mandated by the JEE specification, so we may assume it also to apply to Payara.

In any case, if it is true that the sessions may not be concurrently accessed from multiple threads - and the errors that you got seem to confirm this - then there is no other choice then to create them again in each thread.

RKrahl commented 5 years ago

As an additional note, quote from the official Java EE 7 documentation on Interface javax.jms.Session:

Once a connection has been started, any session with one or more registered message listeners is dedicated to the thread of control that delivers messages to it. It is erroneous for client code to use this session or any of its constituent objects from another thread of control. The only exception to this rule is the use of the session or message consumer close method.

So, indeed, there is no alternative to create a separate session in each thread.