4 Replies Latest reply on Feb 24, 2012 3:14 AM by kiattchaipr

    JBPM stuck when reach AdHocSubprocess and stop executing when reach IntermediateThrowEvent

    kiattchaipr

      Hello everyone,

       

      I integrated my application with JBPM5.1Final and found some problem when I try to execute AdHocSubprocess or IntermediateThrowEvent that contain EscalationEventDefinition inside. This is some code from the application.

       

          KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

          kbuilder.add(ResourceFactory.newFileResource(new File("test.bpmn2")), ResourceType.BPMN2);

          KnowledgeBase knowledgeBase = kbuilder.newKnowledgeBase();

          StatefulKnowledgeSession kSession = knowledgeBase.newStatefulKnowledgeSession();

          kSession.addEventListener(new ProcessEventListener() {

       

                  @Override

                  public void beforeNodeLeft(ProcessNodeLeftEvent arg0) {

                      System.out.println("left: " + arg0.getNodeInstance().getNode().getName());

                  }

       

                  @Override

                  public void beforeNodeTriggered(ProcessNodeTriggeredEvent arg0) {

                      System.out.println("triggered: " + arg0.getNodeInstance().getNode().getName());

                  }

       

                  ....

       

              });

       

          System.out.println("Start")

          kSession.startProcess("process_1");

          //kSession.startProcess("process_2");

          while (!mKSession.getProcessInstances().isEmpty()) {

              try {

                  Thread.sleep(1000);

              } catch (InterruptedException e) {

                  e.printStackTrace();

              }

          }

          System.out.println("Done")

          kSession.dispose();

       

      Output: process_1

      =====================================

      Start

      triggered: StartEvent

      left: StartEvent

      triggered: AdHoc Subprocess

      =====================================

       

      Output: process_2

      =====================================

      Start

      triggered: StartEvent

      left: StartEvent

      triggered: ThrowEscalation

      Done

      =====================================

       

      It seem that it will struck when found the AdHocSubprocess and stop executing when found the IntermediateThrowEvent. In case of IntermediateThrowEvent, it can execute through to the EndEvent if escalationRef property of EscalationEventDefinition inside the IntermediateThrowEvent is not set. Could anyone suggest me what is the cause of this problem?

        • 1. Re: JBPM stuck when reach AdHocSubprocess and stop executing when reach IntermediateThrowEvent
          eaa

          Some anwers and remarks:

           

          • Process are executed in the same thread your application is running, so doing a while (!mKSession.getProcessInstances().isEmpty())  waiting for something is useless.
          • In the case of ad-hoc processes, you need to manually signal the node you want to execute using ksession.signalEvent(). I think you will have to take a look at the tests that shown the behavior of ad-hoc processes in order to get an idea in how to use them. So, the behavior you are experiencing here is the expected. jBPM5 is waiting for someone to signal the node to execute. Your app will be forever in the while() loop. Maybe for your case you can use an embedded subprocess instead of an ad-hoc subprocess.
          • In the case of the intermediate escalation throw event, it seems a bug in jBPM5. Even if nobody is catching that event, the execution should always continue. But maybe I'm wrong here and some of the core developers can correct me.

           

          Best Regards,

          1 of 1 people found this helpful
          • 2. Re: JBPM stuck when reach AdHocSubprocess and stop executing when reach IntermediateThrowEvent
            kiattchaipr

            Thank you so much for your suggestion. Now. I am taking a look at the tests.

            • 3. Re: JBPM stuck when reach AdHocSubprocess and stop executing when reach IntermediateThrowEvent
              eaa

              In the case of ad-hoc processes (same thing for embedded supbrocesses), you have to explicitly say when you want to finish them by putting a End Event Node (not a terminating one). In your case, you need to attach a End Event Node to the Script Task inside the ad-hoc process.

              About the test you are mentioning ( testAdHocSubProcess()), I'm not sure what test is that.

               

              Best Regards,

              • 4. Re: JBPM stuck when reach AdHocSubprocess and stop executing when reach IntermediateThrowEvent
                kiattchaipr

                Thank you so much for your help Esteban Aliverti.

                 

                I tried to to create EndEvent in the ad-hoc subprocess and link it to the ScriptTask as your suggestion but it did not return back to the EndEvent in the Process too. However, I found the intersting thing at the testAdHocSubProcessAutoComplete(). The "completionCondition" property of ad-hoc process was set as <completionCondition xsi:type="tFormalExpression">getActivityInstanceAttribute("numberOfActiveInstances") == 0</completionCondition> in the resource file of the test. When I set the property in my resource file like that, JBPM will return back to the EndEvent in the Process after triggering the ScriptTask.