I use JSF 2 an WebSphere MQ for Messaging (JMS).
I want to know what's the best practice to open / close the QueueConnection? Should I use for each client session one connection and open it on (post-)construction and close it on (pre-) destruction like here?
Or are there better ways to handle the connection? E.g. "Open EntityManager in View" Pattern for JDBC/JPA?
Avoid creating a new connection for each getMessage()
invocation. Create one connection at construct time, save it as an instance variable.
For each getMessage()
call, create a new session, get the message, then close the session.
When you're done, close the connection at destruction time.