JSF中MQ连接的生命周期-连接已关闭 [英] Lifecycle of MQ Connection in JSF - Connection Closed
问题描述
我使用JSF 2和WebSphere MQ for Messaging(JMS).
I use JSF 2 an WebSphere MQ for Messaging (JMS).
我想知道打开/关闭QueueConnection的最佳实践是什么? 我是否应该为每个客户端会话使用一个连接,并在(后)构造上打开它,并在(前)破坏上关闭它,例如
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?
还是有更好的方法来处理连接?例如. 在视图中打开EntityManager" JDBC/JPA的模式吗? >
Or are there better ways to handle the connection? E.g. "Open EntityManager in View" Pattern for JDBC/JPA?
推荐答案
避免为每个getMessage()
调用创建新的连接.在构造时创建一个连接,并将其另存为实例变量.
Avoid creating a new connection for each getMessage()
invocation. Create one connection at construct time, save it as an instance variable.
对于每个getMessage()
呼叫,创建一个新会话,获取消息,然后关闭该会话.
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.
这篇关于JSF中MQ连接的生命周期-连接已关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!