8 Replies Latest reply on Aug 20, 2009 7:25 AM by kukeltje

    Concurrency/Async

    mmusaji

      I've done quite a bit of searching and reading on asynchronous processes in jbpm, and I'm slightly confused as to whether or not JBPM 4.0 can handle parallel processes? (not parallel business processes).

      My unit test calls 3 processes which should be started by the workflow independently of each other.

      <java class="org.workflow.FindProviders" g="276,7,80,40" method="execute" name="find providers">
       <transition name="" to="fork"/>
       </java>
      
       <fork g="298,85,80,40" name="fork">
       <transition g="-62,-18" name="validate red" to="validate red request"/>
       <transition g="-64,-18" name="validate exp" to="validate exp request"/>
       <transition g="-63,-17" name="validate sys" to="validate sys request"/>
       </fork>
      
       <custom continue="async" name="validate red request" class="org.workflow.Validate1" exp="#{myObj}">
       <transition g="-27,-18" name="" to="join"/>
       </custom>
      
       <custom continue="async" name="validate exp request" class="org.workflow.Validate2" exp="#{myObj}">
       <transition g="-27,-18" name="" to="join"/>
       </custom>
      
       <custom continue="async" name="validate sys request" class="org.workflow.Validate3" exp="#{myObj}">
       <transition g="-27,-18" name="" to="join"/>
       </custom>
      
       <join g="267,368,80,40" name="join">
       <transition name="check results" to="evaluate validation results" g="-47,-16"/>
       </join>


      Within classes Validate1, Validate2, Validate3, I put the thread to sleep for different times (2, 3 and 6 seconds). I expected the maximum time for completion would be 6 seconds.

      My Unit test does start each job one after the other which, I am hoping is the reason why this is not working as expected. I'm stuck as to how I would write a Unit test to ensure it is happening in parallel.


      List<Job> jobs = managementService.createJobQuery()
       .processInstanceId(processInstanceId)
       .list();
      
       for(Job job: jobs) {
       managementService.executeJob(job.getId());
       }
      


      Any suggestions would be much appreciated.

      Regards,
      M


        • 1. Re: Concurrency/Async
          mmusaji

          Apologies for the rubbish thread title. It should read Concurrency/Async Unit test case query.

          • 2. Re: Concurrency/Async
            mwohlf

            Hi mmusaji,
            if my understanding of the job scheduler is correct, the execution time for your unit test is 11 sec?
            Maybe you should use threads like so (not tested):

             List<Job> jobs = managementService.createJobQuery()
             .processInstanceId(processInstanceId)
             .list();
            
             for(final Job job: jobs) {
             new Thread(new Runnable() {
             public void run() {
             managementService.executeJob(job.getId());
             }
             }).run();
             }
            


            • 3. Re: Concurrency/Async
              kukeltje

              This way you do not yes the jobexecutor, but jus execute them in sequence. Markus/Mathias/Manfred/... ? correctly notices that, but instead of really using the jobexecutor

              See http://docs.jboss.com/jbpm/v4.0/devguide/html_single/#jobexecutor

              In the examples there are executed programatically for clearness, see http://www.jboss.org/index.html?module=bb&op=viewtopic&t=158906

              • 4. Re: Concurrency/Async
                mmusaji

                I think I need to look in to how to use the jobexecutor.

                I guess what I was asking and looking for confirmation for is that the fork in a workflow can indeed spawn concurrent processes and then join, and that they are not done in sequence if set up correctly?

                • 5. Re: Concurrency/Async
                  kukeltje

                  Correct.

                  • 6. Re: Concurrency/Async
                    kukeltje

                    But keep in mind that it could be that it is not fully concurrent if there are other long runnin jobs in between and the number of threads is limited.

                    • 7. Re: Concurrency/Async
                      mmusaji

                      Thanks again guys.

                      I've included the jobexecutor in my jbpm.cfg.xml and it now kicks off Validate1, Validate2 and Validate3 at the same time, which is what I wanted.

                      However, it doesn't seem to hit the join and seems to end when there are no more "jobs"?

                      I'm going to try and answer my own question by saying I may need some sort of wait-state or event-listener which my Validate classes call to say that it can now continue with the workflow... would I be correct in going down this path to resolve this problem?


                      • 8. Re: Concurrency/Async
                        kukeltje

                        No, with custom nodes you are responsible for making it leave the node in your java classes. See the testcases in the source for examples. Event-listener/wait-state should not be needed.