6 Replies Latest reply on Feb 4, 2009 10:34 AM by kukeltje

    closed JbpmContext in different order then they were created

    tim.shaw

      I have the following code snippet which loads a process instance, loops for unfinished tasks and ends them
      In JBPM 3.1.4 this code works fine, but in 3.2.2 it fails with the following error

      Caused by: org.jbpm.JbpmException: closed JbpmContext in different order then they were created... check your try-finally's around JbpmContexts blocks

      The error is on the jbpmContext.close() in the finally block

      The log.debug points show that the correct context is created initially, but a new context is created within the taskInstance.end() code and this has
      been added to the stack causing the error to occur.


      Can you please shed some light on how this should be handled?

      Thanks



      public void endTask( Long processId ) {
       JbpmContext jbpmContext = JbpmConfiguration.getInstance().createJbpmContext();
       log.debug( "Current context 1" + JbpmConfiguration.getInstance().getCurrentJbpmContext().toString() );
       try {
       ProcessInstance processInstance = jbpmContext.loadProcessInstance( processId );
       List<TaskInstance> taskInstanceList = (List<TaskInstance>)processInstance.getTaskMgmtInstance().getUnfinishedTasks( processInstance.getRootToken() );
       for ( TaskInstance taskInstance : taskInstanceList ) {
       log.debug( "Current context 2" + JbpmConfiguration.getInstance().getCurrentJbpmContext().toString() );
       taskInstance.end();
       log.debug( "Current context 3" + JbpmConfiguration.getInstance().getCurrentJbpmContext().toString() );
       }
       } finally {
       log.debug( "Current context 4" + JbpmConfiguration.getInstance().getCurrentJbpmContext().toString() );
       log.debug( "Closing context" +jbpmContext.toString() );
       jbpmContext.close();
       }
       }