3 Replies Latest reply on Jan 15, 2009 3:00 AM by jaikiran pai

    java.util.ConcurrentModificationException appearing when usi

    colm roy Newbie


      I have some code which ran without exception on jboss 4.0.5. REcently we have moved to jboss 5.0.0 GA and I am seeing alot of java.util.ConcurrentModificationException being thrown.

      Specifically in the following code I have a classs QueueUtil which is used to send JMS text messages.

      public final static void sendMessageToQueue(String queueName, String amessage){
      try{
      QueueSession session=null;
      Queue que=null;
      QueueConnection conn=null;

      InitialContext iniCtx = new InitialContext();
      Object tmp = iniCtx.lookup("ConnectionFactory");
      QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
      conn = qcf.createQueueConnection();

      que = (Queue) iniCtx.lookup(queueName);
      session = conn.createQueueSession(false,
      QueueSession.AUTO_ACKNOWLEDGE);
      QueueSender send = session.createSender(que);
      TextMessage tm = session.createTextMessage(amessage);
      send.send(tm);
      log.info("sendMessage, sent text=" + tm.getText() + " sent queue=" + queueName);
      if(send!=null){ send.close(); }
      if(conn!=null){ conn.close(); }
      if(session!=null){ session.close(); }
      }catch (Exception e){
      log.error("In sendMessageToQueue: caught exception: " + e);
      e.printStackTrace();
      }
      }

      In the server.log I can see the following

      2009-01-14 10:08:39,534 INFO [....utils.QueueUtil] (http-0.0.0.0-8080-15) sendMessage, sent text=EPOS_MESSAGE_TYPE_MARKET_UPDATE,jlee,4497178,S,null,null,null,null,Y,null,N sent queue=queue/testQueue
      2009-01-14 10:08:39,540 ERROR [....utils.QueueUtil] (http-0.0.0.0-8080-15) java.util.ConcurrentModificationException


      What's strange is this is not caught in the catch block so what code is actually logging the exception ? has anyone seen something similiar when moving to Jboss 5 with JMS code ?

        • 1. Re: java.util.ConcurrentModificationException appearing when
          jaikiran pai Master

          Please post the entire exception stacktrace. Do you always see this exception or is this intermittent?

          While posting logs or xml content or code, please remember to wrap it in a code block by using the Code button in the message editor window. Please use the Preview button to ensure that your post is correctly formatted.

          • 2. Re: java.util.ConcurrentModificationException appearing when
            colm roy Newbie

             

            "jaikiran" wrote:
            Please post the entire exception stacktrace. Do you always see this exception or is this intermittent?

            While posting logs or xml content or code, please remember to wrap it in a code block by using the Code button in the message editor window. Please use the Preview button to ensure that your post is correctly formatted.


            Well the thread of execution never enters the catch block to print the stack trace so I never see one.

            Yes, the problem was intermittent.

            I have changed the code to include some logging in between the resource close statements and now the exception is not appearing in the server logs. Is it possible that some resource's internal reference counter is using a datasource that is not thread safe ? i.e. In the changed code below the very fact that I issue a log statement in between resource closing may be enough to remove the underlying resource contention ?

            public final static void sendMessageToQueue(String queueName, String amessage){
            try{
            QueueSession session=null;
            Queue que=null;
            QueueConnection conn=null;
            
            InitialContext iniCtx = new InitialContext();
            Object tmp = iniCtx.lookup("ConnectionFactory");
            QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
            conn = qcf.createQueueConnection();
            
            que = (Queue) iniCtx.lookup(queueName);
            session = conn.createQueueSession(false,
            QueueSession.AUTO_ACKNOWLEDGE);
            QueueSender send = session.createSender(que);
            TextMessage tm = session.createTextMessage(amessage);
            send.send(tm);
            log.info("sendMessage, sent text=" + tm.getText() + " sent queue=" + queueName);
             if(send!=null){ send.close(); }
             log.debug("1");
             if(conn!=null){conn.close();}
             log.debug("2");
             if(session!=null){session.close();}
             log.debug("3");
            }catch (Exception e){
            log.error("In sendMessageToQueue: caught exception: " + e); // Path of execution never enters here
            e.printStackTrace();
            }
             log.debug("DONE.");
            }
            


            Log output is now always showing :
            2009-01-14 13:45:14,127 INFO [....utils.QueueUtil] (http-0.0.0.0-8080-23) sendMessage, sent text=1315712,N sent queue=queue/bidsQueue
            2009-01-14 13:45:14,127 DEBUG [....utils.QueueUtil] (http-0.0.0.0-8080-23) 1
            2009-01-14 13:45:14,128 DEBUG [....utils.QueueUtil] (http-0.0.0.0-8080-23) 2
            2009-01-14 13:45:14,128 DEBUG [...utils.QueueUtil] (http-0.0.0.0-8080-23) 3
            2009-01-14 13:45:14,128 DEBUG [....utils.QueueUtil] (http-0.0.0.0-8080-23) DONE.


            • 3. Re: java.util.ConcurrentModificationException appearing when
              jaikiran pai Master

               

              Well the thread of execution never enters the catch block to print the stack trace so I never see one.


              Not sure why it isn't entering the catch block, but its definitely your application's piece of code which is logging this message:

              2009-01-14 10:08:39,540 ERROR [....utils.QueueUtil] (http-0.0.0.0-8080-15) java.util.ConcurrentModificationException


              which means that the control is definitely reaching the QueueUtil from where it is getting logged. Either that or some class in your application is using an incorrect Logger which is making the log message appear as being logged from QueueUtil