This discussion is archived
5 Replies Latest reply: Apr 24, 2013 7:23 AM by gimbal2 RSS

Question about the use of JMS connections

1005102 Newbie
Currently Being Moderated
Good Morning,

I'm a new user of JMS technology. I'm having some problems with the performance of my application. Specifically, i'm developing a 24x7 application. We are using MessageListener for all consumers.

Doing performance and continuity tests I detected memory leaks in certain JMS classes. After passing a profiler tool, I saw a large amount of ObjectMessage and Message instances. We are not closing the session, MessageListeners, MessageConsumers or Connetion instances because we want to reuse them all the time, and we can't close them because we lose the high availability service.

Reading, the JMS tutorial, I'm saw this paragraph in the "Connection" section:

+"When an application completes, you need to close any connections that you have created. Failure to close a connection can cause resources not to be released by the JMS provider. Closing a connection also closes its sessions and their message producers and message consumers.+
+queueConnection.close();+

+topicConnection.close();+
+Before your application can consume messages, you must call the connection's start method; for details, see Section 3.5, "Message Consumers." If you want to stop message delivery temporarily without closing the connection, you call the stop method."+

Should I close the connection as the last paragraph say?. If so, I don't know how to do it without lose the service, because if I call "close" method on the connection and immediatelyi start it, i will lose all my consumers and producers for a little time.

Any suggestion?

Thank you in advance,

Regards
  • 1. Re: Question about the use of JMS connections
    nigeldeakin Explorer
    Currently Being Moderated
    1002099 wrote:

    +"When an application completes, you need to close any connections that you have created. Failure to close a connection can cause resources not to be released by the JMS provider. Closing a connection also closes its sessions and their message producers and message consumers.+
    +queueConnection.close();+

    +topicConnection.close();+
    +Before your application can consume messages, you must call the connection's start method; for details, see Section 3.5, "Message Consumers." If you want to stop message delivery temporarily without closing the connection, you call the stop method."+

    Should I close the connection as the last paragraph say?. If so, I don't know how to do it without lose the service, because if I call "close" method on the connection and immediatelyi start it, i will lose all my consumers and producers for a little time.
    You should close a connection when you have no further use for it as this will release resources.

    You must start a connection if you want to receive messages from it.

    Most applications don't use stop(). However if your application needs to temporarily pause delivery of messages (to the application) for some reason, call stop(). When your application wants delivery of messages (to the application) to restart, call start() again.

    Nigel
  • 2. Re: Question about the use of JMS connections
    1005102 Newbie
    Currently Being Moderated
    Thanks for your reply Nigel,

    Now I understand the use of stop and start methods. However, I'm still confused with close method. In my application, i'm using one connection for create different sessions, consumers and producers. All of them, are working constantly, because we can't stop the service (and the message activity it's generous). I suppose that my memory leaks comes from the detail that you say about the resources and their releases. Now my question is: How can I close my connection (using "close" method, or similar that release resources), without stopping my activity, for release all the resources that makes me leak memory?.

    Thanks a lot

    Regards

    Miguel
  • 3. Re: Question about the use of JMS connections
    gimbal2 Guru
    Currently Being Moderated
    I don't think that closing the connection is really the answer since you obviously are not done with it until you shut down your entire service.

    The real question is: why are those resources you found through profiling sticking around in memory? That probably cannot be answered in the general sense - JMS is only an API, you are using a particular implementation of that API and the problem may reside within that implementation. You mentioned that you found the memory usage in specific classes - which ones exactly?
  • 4. Re: Question about the use of JMS connections
    1005102 Newbie
    Currently Being Moderated
    Hi gimbal2,

    Absolutely agree with you. My suspicions are more oriented to the implementation I'm using (ActiveMQ - classes that I'm detected has activemq signature), and of course, from bad use that I'm taking in my SW.
    I'm coming to this forum, searching recommendations (and experiences) of best practices for 24x7 applications that use JMS as communication method, and trying to find the answer to my problem.
    After I noticed the API fragment, that I pasted before in relation with the "close" method on the connection specification, I would like to know, if these acumulated resources (that i'm detecting profiling my application with an specific implementation), will be release, if I'm close the connection at any moment.

    Thanks

    Miguel
  • 5. Re: Question about the use of JMS connections
    gimbal2 Guru
    Currently Being Moderated
    I would still direct your questions to an ActiveMQ forum or mailing list if I were you. At least in such a place you reach a large pool of people who actually use the technology. The website lists plenty of resources where you can ask for help, such as:

    http://activemq.2283324.n4.nabble.com/ActiveMQ-User-f2341805.html

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points