3 Replies Latest reply on Apr 14, 2008 4:38 AM by nathan dennis

    ConcurrentModificationException While not under load

    nathan dennis Expert

      Having trouble with an exception just after ajax call.
      jboss 4.2.2
      seam 2.0.1.ga
      richfaces 3.2


      the expection


      19:04:00,004 ERROR [SeamPhaseListener] uncaught exception
      java.util.ConcurrentModificationException
              at java.util.SubList.checkForComodification(AbstractList.java:855)
              at java.util.SubList.size(AbstractList.java:728)
              at org.jboss.seam.contexts.EntityBeanList.passivateAll(EntityBeanList.java:68)
              at org.jboss.seam.contexts.AbstractEntityBeanCollection.passivate(AbstractEntityBeanCollection.java:43)
              at org.jboss.seam.contexts.ServerConversationContext.isAttributeDirty(ServerConversationContext.java:307)
              at org.jboss.seam.contexts.ServerConversationContext.flush(ServerConversationContext.java:280)
              at org.jboss.seam.contexts.Contexts.flushAndDestroyContexts(Contexts.java:371)
              at org.jboss.seam.contexts.FacesLifecycle.endRequest(FacesLifecycle.java:112)
              at org.jboss.seam.jsf.SeamPhaseListener.afterRenderResponse(SeamPhaseListener.java:502)
              at org.jboss.seam.jsf.SeamPhaseListener.afterServletPhase(SeamPhaseListener.java:235)
              at org.jboss.seam.jsf.SeamPhaseListener.afterPhase(SeamPhaseListener.java:182)
              at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:280)
              at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
              at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
              at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:147)
              at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:276)
              at org.ajax4jsf.Filter.doFilter(Filter.java:175)
              at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
              at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
              at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
              at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
              at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
              at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
              at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
              at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
              at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
              at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
              at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
              at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
              at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
              at java.lang.Thread.run(Thread.java:595)
      19:04:00,006 ERROR [SeamPhaseListener] swallowing exception
      java.util.ConcurrentModificationException
              at java.util.SubList.checkForComodification(AbstractList.java:855)
              at java.util.SubList.size(AbstractList.java:728)
              at org.jboss.seam.contexts.EntityBeanList.passivateAll(EntityBeanList.java:68)
              at org.jboss.seam.contexts.AbstractEntityBeanCollection.passivate(AbstractEntityBeanCollection.java:43)
              at org.jboss.seam.contexts.ServerConversationContext.isAttributeDirty(ServerConversationContext.java:307)
              at org.jboss.seam.contexts.ServerConversationContext.flush(ServerConversationContext.java:280)
              at org.jboss.seam.contexts.Contexts.flushAndDestroyContexts(Contexts.java:371)
              at org.jboss.seam.contexts.FacesLifecycle.endRequest(FacesLifecycle.java:112)
              at org.jboss.seam.jsf.SeamPhaseListener.afterRenderResponse(SeamPhaseListener.java:502)
              at org.jboss.seam.jsf.SeamPhaseListener.afterServletPhase(SeamPhaseListener.java:235)
              at org.jboss.seam.jsf.SeamPhaseListener.afterPhase(SeamPhaseListener.java:182)
              at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:280)
              at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
              at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
              at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:147)
              at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:276)
              at org.ajax4jsf.Filter.doFilter(Filter.java:175)
              at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
              at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
              at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
              at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
              at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
              at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
              at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
              at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
              at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
              at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
              at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
              at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
              at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
              at java.lang.Thread.run(Thread.java:595)
      


      there are a bunch of ajax request on this page.. and this two are the only ones giving trouble.


      now some code.


      @Stateful
      @Name("picAction")
      @Scope(ScopeType.CONVERSATION)
      public class PicAction implements PicLocal, DropListener, Serializable 
      
      ....
      
           public void switchLayer(boolean layer, int layerindex){
                if (layer == false && this.layerselectlock==false && this.activelayer >= 0){
                     saveOrder();
                     if(activelayer < layerframe2.size() -1 ){
                               subreindex = layerframe2.subList(activelayer + 1, layerframe2.size());
                          
                          long startingpoint = subreindex.get(0).getPoz();
                          log.info("after sublist");
                          for(int i = 0; i < subreindex.size(); i++ ){     
                                           subreindex.get(i).setPoz(startingpoint - (long)1 + (long)i );
                                    entityManager.merge(subreindex.get(i));                    
                     }
                                         if(layerframe2.get(activelayer).getMark() == 107){
                               FileDeleteLocal removelayer = (FileDeleteLocal) Component.getInstance("fileDeleteAction");
                               removelayer.deleteMedia(layerframe2.get(activelayer).getLayername(),
                                              layerframe2.get(activelayer).getUserid());
                          }else {               entityManager.remove(entityManage               .find(Layers.class, layerframe2.get(activelayer).getId()));
                          }
                     layerselectlock = true;
                     initEdit(); //reinitialize list
               }....
                
      



           function deleteLayerTrash( cid ){
                document.getElementById('ajaxdisabled').style.visibility='visible';
                Seam.Remoting.getContext().setConversationId( cid );
                Seam.Component.getInstance("removeLayerAction").removeLayer(false, rerenderSideBar);
                }
      



      onclick="deleteLayerTrash( #{conversation.id} )"
      



      this quantity of code may be worthless.. this app is so large... it is becoming cumbersome.


      The first time this is executed it works fine. It will throw the exception on the second or third execution WITHOUT FAIL.
      any direction would be greatly appreciated. 

        • 1. Re: ConcurrentModificationException While not under load
          Tom Goring Apprentice

          It's worth reading the richfaces manual:



          5.4.2. Queue and Traffic Flood Protection
                  "eventsQueue" attribute defines the name of the queue that will be used to order upcoming Ajax requests.
                  By default, RichFaces does not queue Ajax requests. If events are produced simultaneously, they will come
                  to the server simultaneously. JSF implementations (especially, the very first ones) does not guaranty that
                  the request that comes first will be served or passed into the JSF lifecycle first. The order how the server
                  side data will be modified in case of simultaneous request might be unpredictable. Usage of eventsQueue
                  attribute allows to avoid possible mess. Define the queue name explicitly, if you expect intensive Ajax
                  traffic in your application.
                  The next request posted in the same queue will wait until the previos one is not processed and Ajax
                  Response is returned back if the "eventsQueue" attribute is defined. In addition, Richfaces starts to remove
                  from the queue "similar" requests. "Similar'"requests are the requests produced by the same event. For
                  example, according to the following code, only the newest request will be sent to the server if you type
                  very fast and has typed the several characters already before the previous Ajax Response is back.
                   ...
                         <h:inputText value="#{userBean.name}">
                              <a4j:support event="onkeyup" eventsQueue="foo" reRender="bar" />
                         </h:inputText>
          


          • 2. Re: ConcurrentModificationException While not under load
            nathan dennis Expert

            i cant tell if from the trace... but you may be onto something.


            is where a way of Queueing ajax request generated from Seam.Remote?

            • 3. Re: ConcurrentModificationException While not under load
              nathan dennis Expert

              ignore that stupid question... thats the equivalent of asking how do i walk to the store in a bus?


              the eventsQueue wasnt actually the source of that exception. it was an array that was not being reinitialized... HOWEVER,, the was the source of many other weird behaviors i was having and your absolutely correct.. i should pay more attention to the manual.


              i had read that pharagraph about three months ago, but since i wasnt having problems with such things at the time,,, i guess it didnt register.
              five kudos.