4 Replies Latest reply on Sep 19, 2011 11:51 AM by Bernd Eckenfels

    undeploy for MDB does not invoke @PreDestroy

    Bernd Eckenfels Novice

      I am using AS 7.0.1-final on Windows XP with 32bit JDK1.6_26 in the standalone-preview.xml configuration which uses hornetq-ra which is pooled-connection-factory for in-vm.


      I wrote a EJB-JAR App which contains a single MessageDrivenBean and another WAR, with a JSP to send test messages.


      If I deploy the  JAR, the @MessageDriven class annotation sucessfully connects to the specified HornetMQ JMS Queue, and when I sent a Test message the @PostConstruct method is invoked. It will process JMS Messages (with some issues, will open a seperate thread for this).


      However, here is my Problem: when I use CLI "undeloy" or delete the standalone/deployments/*.jar file, the AS outputs, that it is "stopping the deployment", but it will NOT invoke the method associated with the @PreDestroy annotation first (resulting in a ressource leak in my case).


      It also seems, that it is not unregistering the listener before stopping the deployment, since JMS messages will create some exceptions in the undeploy phase:


      19:54:37,198 INFO  [stdout] (Thread-13 (group:HornetQ-client-global-threads-8955918)) onMessage() START ID:baa5f531-dfc3


      19:54:38,589 INFO  [org.jboss.as.server.controller] (DeploymentScanner-threads - 1) Undeployed "net.eckenfels.as7example


      19:54:39,198 INFO  [stdout] (Thread-13 (group:HornetQ-client-global-threads-8955918)) onMessage() DONE  ID:baa5f531-dfc3


      19:54:39,198 ERROR [org.hornetq.ra.inflow.HornetQMessageHandler] (Thread-13 (group:HornetQ-client-global-threads-8955918

      )) Failed to deliver message: java.lang.NullPointerException

              at org.hornetq.ra.inflow.HornetQMessageHandler.onMessage(HornetQMessageHandler.java:287)

              at org.hornetq.core.client.impl.ClientConsumerImpl.callOnMessage(ClientConsumerImpl.java:866)

              at org.hornetq.core.client.impl.ClientConsumerImpl.access$100(ClientConsumerImpl.java:44)

              at org.hornetq.core.client.impl.ClientConsumerImpl$Runner.run(ClientConsumerImpl.java:983)

              at org.hornetq.utils.OrderedExecutorFactory$OrderedExecutor$1.run(OrderedExecutorFactory.java:100)

              at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_26]

              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_26]

              at java.lang.Thread.run(Thread.java:662) [:1.6.0_26]

        • 1. Re: undeploy for MDB does not invoke @PreDestroy
          Carlo de Wolf Master

          A bug in MessageDrivenComponent. It does not start/stop the Pool.

          I've opened up AS7-1847.

          • 2. Re: undeploy for MDB does not invoke @PreDestroy
            Bernd Eckenfels Novice

            Thank you Carlo.


            I also see a strange behaviour in processing the messages. My onMessage() Method does a sleep(2*1000) for testing the load case. When I send a few messages, it first starts to create new instances which are processing more and more messages in parallel.


            But when 5 MDB Instances are started, only a single worker thread keeps processing messages:


            Here you see a test, 1 message, then 2 messages with 2s pause, and then 2 quick messages: The system correctly initiizes one instance for the first 3 messages and another one for the next two messages in parallel:


            02:31:25,090 INFO  [org.jboss.as.server.controller] (DeploymentScanner-threads - 2) Deployed "net.eckenfels.as7example.e


            02:31:25,090 INFO  [org.jboss.as.server.controller] (DeploymentScanner-threads - 2) Deployed "EJB3MDBWeb.war"

            02:31:39,949 INFO  [stdout] (http-localhost- Sent JMS Message ID=ID:93516c9d-e18d-11e0-90c2-080027008c43

            02:31:39,980 INFO  [EJB3MDB] (Thread-0 (group:HornetQ-client-global-threads-3178554)) EJB3MDB.initialize(): done.

            02:31:39,980 INFO  [stdout] (Thread-0 (group:HornetQ-client-global-threads-3178554)) onMessage() START ID:93516c9d-e18d-11e0-90c2-080027008c43

            02:31:41,980 INFO  [stdout] (Thread-0 (group:HornetQ-client-global-threads-3178554)) onMessage() DONE  ID:93516c9d-e18d-11e0-90c2-080027008c43

            02:31:46,434 INFO  [stdout] (http-localhost- Sent JMS Message ID=ID:97313ede-e18d-11e0-90c2-080027008c43

            02:31:46,434 INFO  [stdout] (Thread-2 (group:HornetQ-client-global-threads-3178554)) onMessage() START ID:97313ede-e18d-11e0-90c2-080027008c43

            02:31:48,434 INFO  [stdout] (Thread-2 (group:HornetQ-client-global-threads-3178554)) onMessage() DONE  ID:97313ede-e18d-11e0-90c2-080027008c43

            02:31:55,574 INFO  [stdout] (http-localhost- Sent JMS Message ID=ID:9ca19c2f-e18d-11e0-90c2-080027008c43

            02:31:55,574 INFO  [stdout] (Thread-0 (group:HornetQ-client-global-threads-3178554)) onMessage() START ID:9ca19c2f-e18d-11e0-90c2-080027008c43

            02:31:55,934 INFO  [stdout] (http-localhost- Sent JMS Message ID=ID:9cdad4a0-e18d-11e0-90c2-080027008c43

            02:31:55,949 INFO  [EJB3MDB] (Thread-1 (group:HornetQ-client-global-threads-3178554)) EJB3MDB.initialize(): done.

            02:31:55,949 INFO  [stdout] (Thread-1 (group:HornetQ-client-global-threads-3178554)) onMessage() START ID:9cdad4a0-e18d-11e0-90c2-080027008c43

            02:31:57,574 INFO  [stdout] (Thread-0 (group:HornetQ-client-global-threads-3178554)) onMessage() DONE  ID:9ca19c2f-e18d-11e0-90c2-080027008c43

            02:31:57,949 INFO  [stdout] (Thread-1 (group:HornetQ-client-global-threads-3178554)) onMessage() DONE  ID:9cdad4a0-e18d-11e0-90c2-080027008c43


            This repeats till 5 instances are started. When I then keep generating messages it suddenly degenerates and only a single worker is processing the messages (slowly):


            02:36:47,734 INFO  [stdout] (Thread-6 (group:HornetQ-client-global-threads-3178554)) onMessage() START ID:4ac7fa2a-e18e-11e0-90c2-080027008c43

            02:36:48,047 INFO  [stdout] (Thread-1 (group:HornetQ-client-global-threads-3178554)) onMessage() START ID:4af7bcbb-e18e-11e0-90c2-080027008c43

            02:36:48,047 INFO  [stdout] (http-localhost- Sent JMS Message ID=ID:4af7bcbb-e18e-11e0-90c2-080027008c43

            02:36:48,359 INFO  [stdout] (http-localhost- Sent JMS Message ID=ID:4b250e4c-e18e-11e0-90c2-080027008c43

            02:36:48,625 INFO  [stdout] (http-localhost- Sent JMS Message ID=ID:4b4d7ddd-e18e-11e0-90c2-080027008c43

            02:36:48,891 INFO  [stdout] (http-localhost- Sent JMS Message ID=ID:4b78857e-e18e-11e0-90c2-080027008c43

            02:36:49,734 INFO  [stdout] (Thread-6 (group:HornetQ-client-global-threads-3178554)) onMessage() DONE  ID:4ac7fa2a-e18e-11e0-90c2-080027008c43

            02:36:50,047 INFO  [stdout] (Thread-1 (group:HornetQ-client-global-threads-3178554)) onMessage() DONE  ID:4af7bcbb-e18e-11e0-90c2-080027008c43

            02:36:50,063 INFO  [stdout] (Thread-1 (group:HornetQ-client-global-threads-3178554)) onMessage() START ID:4b250e4c-e18e-11e0-90c2-080027008c43

            02:36:52,063 INFO  [stdout] (Thread-1 (group:HornetQ-client-global-threads-3178554)) onMessage() DONE  ID:4b250e4c-e18e-11e0-90c2-080027008c43

            02:36:52,063 INFO  [stdout] (Thread-1 (group:HornetQ-client-global-threads-3178554)) onMessage() START ID:4b4d7ddd-e18e-11e0-90c2-080027008c43

            02:36:54,063 INFO  [stdout] (Thread-1 (group:HornetQ-client-global-threads-3178554)) onMessage() DONE  ID:4b4d7ddd-e18e-11e0-90c2-080027008c43

            02:36:54,078 INFO  [stdout] (Thread-1 (group:HornetQ-client-global-threads-3178554)) onMessage() START ID:4b78857e-e18e-11e0-90c2-080027008c43

            02:36:56,078 INFO  [stdout] (Thread-1 (group:HornetQ-client-global-threads-3178554)) onMessage() DONE  ID:4b78857e-e18e-11e0-90c2-080027008c43


            Any idea how to furhter debug this? In the thread dump I see the idle worker threads in the normal "unsafe park" where they are waiting to be triggered. Next on my Agenda is to try it with a 7.1 snapshot.

            • 3. Re: undeploy for MDB does not invoke @PreDestroy
              Carlo de Wolf Master

              Best open up a new forum thread for this one. Also attach a thread dump to it.

              • 4. Re: undeploy for MDB does not invoke @PreDestroy
                Bernd Eckenfels Novice

                Thansk Carlo for looking into that. I actually found the problem. The MDB pooling seems to work fine. The problem was with the test sender (generator servlet), where I created a MessageProducer and a MessageConsumer, but only used the Producer. I guess do to prefetch it somewhat sucked up the messages so the could not be distributed. With the producer only, I can see a parallel processing with 15 Threads now.


                Here is part of the sender code with the unneeded line:


                String queueName = "queue/MyQueue";
                String factory = "java:/JmsXA";
                <p>Every time you invoke this JSP page, a JMS TextMessage is sent to the queue=<%= queueName %> via JNDI=<%= factory %></p>
                        Context ic = new InitialContext();
                        ConnectionFactory cf = (ConnectionFactory)ic.lookup(factory);
                        javax.jms.Connection conn = cf.createConnection();
                        String msgID = "failed";
                            Queue queue = (Queue)ic.lookup(queueName);

                            Session jmsSes = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
                            MessageProducer publisher = jmsSes.createProducer(queue);
                            --MessageConsumer consumer  = jmsSes.createConsumer(queue);--


                            TextMessage message = jmsSes.createTextMessage("Hello!");
                            msgID = message.getJMSMessageID();
                            out.println("Sent JMS Message ID=" + msgID + "<p>");
                            System.out.println("Sent JMS Message ID=" + msgID);
                    catch (NamingException e)
                        out.println("Exception: " + e);
                    catch (JMSException e)
                        out.println("Exception: " + e);