Long lived JMS sessions. Is Keeping JMS connections / JMS sessions always opened a bad practice?

前端 未结 5 687
野性不改
野性不改 2021-02-14 08:25

Is keeping JMS connections / sessions / consumer always open a bad practice?

Code draft example:

// app startup code

ConnectionFactory cf = (ConnectionF         


        
相关标签:
5条回答
  • 2021-02-14 08:59

    That is a very common and acceptable practice when dealing with long lived connections. For many JMS servers it is in fact preferable to creating a new connection each time it is needed.

    0 讨论(0)
  • 2021-02-14 09:01

    In our app, we will have connections/sessions/consumers/producers open for months at a time. We've had to work with our vendor (BEA) to make that work reliably. But any troubles with that is a bug the vendor needs to fix.

    0 讨论(0)
  • 2021-02-14 09:10

    The choice of keeping connection/session/producer/consumer open for long or not should be based on the frequency at which producer/consumer sends/receives messages.

    If a producer sends or a consumer receives messages frequently then the connections/sessions/producer/consumer should be kept open. On the other hand if messages send/receive is infrequent then it is not good keeping these JMS objects open will consume system resources like sockets.

    0 讨论(0)
  • 2021-02-14 09:11

    Agreed. Here are some good tips on how to use JMS efficiently which includes keeping around connections/sessions/producers/consumers.

    You might also want to check the recommendation on using transactions too if you are interested in maximising performance.

    0 讨论(0)
  • 2021-02-14 09:12

    FYI, there is no need to close the sessions, producers, and consumers of a closed connection( javax.jms.Connection ). The code below should be enough to release the resources:

    try { 
            this.connection.close();
        } catch (JMSException e) {
            //
        }
    
    0 讨论(0)
提交回复
热议问题