5 Replies Latest reply on Jan 12, 2007 10:24 AM by timfox

    MessageConsumer thread never goes away

    chipschoch

      I have a service that listens to and services JMS queues. I have been starting and stopping it and have been watching the thread count grow. Through a tedious trial and error session I have determined that the thread that is produced when javax.jms.Session.createConsumer() never goes away.

      I am calling MessageConsumer.close() but the thread stays around. Even after I undeploy my service the thread that was created by it remains. I did this by remote debugging my JBoss server using eclipse and looking at the threads. I even wrote a simple test program that crated a consumer then closed it and I stepped through it watching it create the thread. When I stepped through the close method it di ot go away.

      Has anyone else seen this? This is a huge show stopper for us, as this won't run like this too long before all the resources are exhausted.

        • 1. Re: MessageConsumer thread never goes away
          timfox

          Please say what version of JBM, AS you are using and post your code.

          • 2. Re: MessageConsumer thread never goes away
            chipschoch

            I am not sure what JBM is but I am running jdk1.5.0_10, JBoss 4.0.5 GA, and Messaging 1.0.1GA. It would be difficult to post my actual code in this forum but it is essentially executing the following in the onMessage().

            Properties p = new Properties ();

            p.put (Context.PROVIDER_URL, "jnp://localhost:1099");
            p.put (Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
            p.put (Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");

            InitialContext context = new InitialContext (p);

            MessageConsumer consumer = null;
            int count = 0;
            Queue queue = (Queue) context.lookup (queuename);

            try
            {
            consumer = jmssession.createConsumer (queue);

            ... do something here
            ]
            consumer.close();
            }


            catch (Exception e)
            {
            System.err.println( "Exception while trying to clear error queue");
            }


            I verified that the createConsumer line is where the thread is being created and the thread remains when I undeploy my service. Each time a message goes through a new thread is created that never goes away.

            Thanks

            • 3. Re: MessageConsumer thread never goes away
              timfox

              JBM is JBoss Messaging.

              Are your jms client and jms server running in the same VM?

              Threads for server side consumers are taken from a server side "pool" which has a default max size of 200.

              How many threads are you seeing?

              If 200 is too high for you, you can reduce the number by adding an attribute QueuedExecutorPoolSize on the serverpeer specifying the max size you want.

              • 4. Re: MessageConsumer thread never goes away
                chipschoch

                Yes, my mbean that is servicing my jms queues is running in the same jvm as the messaging service, that is, the mbean is deployed in the same default server that is running messaging.

                So if I understand you correctly, the thread count will continue to grow until it reaches 200 then it will begin to reuse the consumer threads?

                Forgive my ignorance but I am new to JBoss. To make it absolutely clear for me, and any other noobs interested, are you saying that in order to change this (for example to 50) I would add:

                50
                to messaging-service.xml under the ServerBean mbean?

                Thanks for your rapid response.

                • 5. Re: MessageConsumer thread never goes away
                  timfox

                  Yes, add an attribute:

                  <attribute name="QueuedExecutorPoolSize">50</attribute>
                  


                  in the server peer mbean config