3 Replies Latest reply on Dec 18, 2015 6:28 PM by Arif Mohammed

    Sporadic java.util.ConcurrentModificationException while retrieving tasks.

    Arif Mohammed Novice

      Hello jBPM Team,

         I am getting ConcurrentModificationException while retrieving task list and it is not always but sporadic. Following is the complete details about the problem, please let me know if further information is needed.

      Envirnoment

           - jBPM6 using in embedded mode within spring application.

           - snapshot version of 6.1.0

           - Session per process instance strategy

           - TaskService is a shared object across multiple threads for retrieving tasks from DB, following is the spring configuration. please note that taskService reference is injected as singleton bean and re-used across different threads for retrieving of tasks. Is there any issue in using taskService like this ??

       

        <bean id="runtimeEnvironment" class="org.kie.spring.factorybeans.RuntimeEnvironmentFactoryBean">
          <property name="type" value="DEFAULT"/>
          <property name="entityManagerFactory" ref="jbpmEMF"/>
          <property name="transactionManager" ref="jbpmTxManager"/>
          <property name="assets">
            <map>
              <entry key-ref="approval-process"><util:constant static-field="org.kie.api.io.ResourceType.BPMN2"/></entry>
            </map>
          </property>
          <property name="taskService" ref="taskService"/>
          <property name="registerableItemsFactory" ref="rasRegisterableItemsFactory"/>
        </bean>   
        <bean id="runtimeManager" class="org.kie.spring.factorybeans.RuntimeManagerFactoryBean" destroy-method="close">
          <property name="identifier" value="spring-rm"/>
          <property name="runtimeEnvironment" ref="runtimeEnvironment"/>
          <property name="type" value="PER_PROCESS_INSTANCE"/>
        </bean>
        <bean id="taskService" class="org.kie.spring.factorybeans.TaskServiceFactoryBean" destroy-method="close">
          <property name="entityManagerFactory" ref="jbpmEMF"/>
          <property name="transactionManager" ref="jbpmTxManager"/>
          <property name="userGroupCallback" ref="userGroupCallback"/>
          <property name="listeners">
            <list>
              <bean class="com.xyz.myco.TaskLifeCycleEventListener" />
            </list>
          </property>                    
        </bean>     
      

          

      And here is the code how tasks are retrieved.

       

      public void getTaskLists(){
        ...
        // taskService is injected by spring
        InternalTaskService internalService = (InternalTaskService)taskService;
        List<Status> sts = new ArrayList<Status>();
        sts.add(Status.Ready);
        sts.add(Status.Reserved);
        sts.add(Status.InProgress);        
        sts.add(Status.Completed);
        List<TaskSummary> list = internalService.getTasksAssignedAsPotentialOwnerByStatusByGroup(null, groupIds,sts, locale);
      
        
      
         
      

       

      And following is the exception snippet while calling getTasksAssignedAsPotentialOwnerByStatusByGroup


        java.util.ConcurrentModificationException

              java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372)

              java.util.AbstractList$Itr.next(AbstractList.java:343)

              org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:263)

              org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:187)

              org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:326)

              org.hibernate.event.internal.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:59)

              org.hibernate.internal.SessionImpl.autoFlushIfRequired(SessionImpl.java:1053)

              org.hibernate.internal.SessionImpl.list(SessionImpl.java:1108)

              org.hibernate.internal.QueryImpl.list(QueryImpl.java:101)

              org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:252)

              org.jbpm.services.task.persistence.JPATaskPersistenceContext.queryStringWithParameters(JPATaskPersistenceContext.java:475)

              org.jbpm.services.task.persistence.JPATaskPersistenceContext.queryWithParametersInTransaction(JPATaskPersistenceContext.java:344)

              org.jbpm.services.task.impl.TaskQueryServiceImpl.getTasksAssignedAsPotentialOwnerByStatusByGroup(TaskQueryServiceImpl.java:263)

              org.jbpm.services.task.commands.GetTaskAssignedAsPotentialOwnerCommand.execute(GetTaskAssignedAsPotentialOwnerCommand.java:70)

              org.jbpm.services.task.commands.GetTaskAssignedAsPotentialOwnerCommand.execute(GetTaskAssignedAsPotentialOwnerCommand.java:15)

              org.jbpm.services.task.commands.TaskCommandExecutorImpl$SelfExecutionCommandService.execute(TaskCommandExecutorImpl.java:65)

              org.drools.core.command.impl.AbstractInterceptor.executeNext(AbstractInterceptor.java:41)

              org.jbpm.services.task.persistence.TaskTransactionInterceptor.execute(TaskTransactionInterceptor.java:54)

              org.jbpm.services.task.commands.TaskCommandExecutorImpl.execute(TaskCommandExecutorImpl.java:40)

              org.jbpm.services.task.impl.command.CommandBasedTaskService.getTasksAssignedAsPotentialOwnerByStatusByGroup(CommandBasedTaskService.java:423)

              com.xyz.myco.ProcessUtility.getTaskLists(ProcessUtility.java:293)

        • 1. Re: Sporadic java.util.ConcurrentModificationException while retrieving tasks.
          Arif Mohammed Novice

          I am getting another exception and I believe it is something wrong with reusing taskService object. Can't we reuse the taskService object across multiple threads ??

          This time I am making a call to getTaskById as follows

           

          Task tsk = taskService.getTaskById(summary.getId());
          
          • org.hibernate.exception.GenericJDBCException: The statement is closed.

                  org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:52)

                  org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)

                  org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)

                  org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:129)

                  org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)

                  $Proxy76.setLong(Unknown Source)

                  org.hibernate.type.descriptor.sql.BigIntTypeDescriptor$1.doBind(BigIntTypeDescriptor.java:57)

                  org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:92)

                  org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:305)

                  org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:300)

                  org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1907)

                  org.hibernate.loader.Loader.bindParameterValues(Loader.java:1878)

                  org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1756)

                  org.hibernate.loader.Loader.doQuery(Loader.java:828)

                  org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:289)

                  org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)

                  org.hibernate.loader.Loader.loadCollection(Loader.java:2175)

                  org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:61)

                  org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:622)

                  org.hibernate.event.internal.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:82)

                  org.hibernate.internal.SessionImpl.initializeCollection(SessionImpl.java:1606)

                  org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:379)

                  org.hibernate.collection.internal.AbstractPersistentCollection.read(AbstractPersistentCollection.java:112)

                  org.hibernate.collection.internal.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:137)

                  org.hibernate.collection.internal.PersistentBag.size(PersistentBag.java:242)

                  org.jbpm.services.task.persistence.TaskTransactionInterceptor.postInit(TaskTransactionInterceptor.java:202)

                  org.jbpm.services.task.persistence.TaskTransactionInterceptor.execute(TaskTransactionInterceptor.java:55)

                  org.jbpm.services.task.commands.TaskCommandExecutorImpl.execute(TaskCommandExecutorImpl.java:40)

                  org.jbpm.services.task.impl.command.CommandBasedTaskService.getTaskById(CommandBasedTaskService.java

          • 2. Re: Sporadic java.util.ConcurrentModificationException while retrieving tasks.
            Arif Mohammed Novice

            does any one has any idea about what is wrong with this ?

            • 3. Re: Sporadic java.util.ConcurrentModificationException while retrieving tasks.
              Arif Mohammed Novice

              Hi Maciej,

               

                As per your blog we can configure jBPM in spring based applications in 2 ways with respect to task service, however the second approach seems to be not working if this kind of setup is used in a web application where concurrent users will be accessing the application.

               

                 The moment I removed the Shared Task Service and started using the first approach the problem seems to be solved.