8 Replies Latest reply on Jul 8, 2010 8:32 AM by aguizar

    Possible performance problem caused by autoSaveProcessInstances

    richard.qin

      autoSaveProcessInstances is a List type field of JbpmContext class, which contains the processInstance needed to persistent to database.

       

      List autoSaveProcessInstances = null;
      

       

      Due to the List type of autoSaveProcessInstances, the same processInstance can be repeatedly added to autoSaveProcessInstances by JbpmContext.addAutoSaveProcessInstance method.

       

        public void addAutoSaveProcessInstance(ProcessInstance processInstance)
        {
          if (autoSaveProcessInstances == null)
            autoSaveProcessInstances = new ArrayList();
          autoSaveProcessInstances.add(processInstance);
        }
      

       

      When invoked by JbpmContext.close method, JbpmContext.autoSave will iterate each processInstance in the autoSaveProcessInstances to save, thus the processInstance be saved repeatedly.

       

        void autoSave()
        {
          if (autoSaveProcessInstances != null)
          {
            Iterator iter = autoSaveProcessInstances.iterator();
            while (iter.hasNext())
            {
              ProcessInstance processInstance = (ProcessInstance)iter.next();
              save(processInstance);
              iter.remove();
            }
          }
        }
      

       

      In my web app based seam 2.2.0, jbpm 3.2.5.sp5, a jsf request will cause the same processInstance to be saved more than 2000 times. How about change the List type of autoSaveProcessInstances to the Set type? Any suggestion are greatly appreciated.