1 Reply Latest reply on Feb 4, 2010 5:53 AM by lucazammarchi

    Multiple Subprocess - jBPM 3.3.1

    lucazammarchi

      Hi All,

      I need to create a process that polling a database table and then creates one subprocess instance for each records in the database table.

       

      I use the Process-State with a "loop" node that return to the Process-State node for each records. This solution works, but each sub process was running sequentially.

       

      Anyone have any ideas how I can create multiple subprocess that running in the same time?

       

      I just try to use a fork with four Process-State node..but every process running sequentially.

       

      Thanks for any suggestion.

       

      Best Regards.

       

      Luca Zammarchi

        • 1. Re: Multiple Subprocess - jBPM 3.3.1
          lucazammarchi

          Hi,

          I implemented a solution that has the same result:

           

          - I created some "process instances" from one process definition

          - then I created an ExecuteNodeJob for each process instance and I sent it to the MessageService.

          - In ArrayList I was putting all process instance ids

          - With a timer I was checking all process and wait for all processes.

           

          Below the function I use to create the process:

          public long createSubProcess(ExecutionContext executionContext,
                         String processName,HashMap variabili,boolean signalToken ){
          
          
                          //Create process instance
                    ProcessInstance subProcessInstance = executionContext.getJbpmContext().newProcessInstance(processName);
          
          
          
                          //Setting any variable 
                          Iterator iterator = variabili.keySet().iterator();
                    while(iterator.hasNext()){
                         String key=(String)iterator.next();
                         contextInstance.setVariable(key, variabili.get(key));
                    }
          
                    Token token=subProcessInstance.getRootToken();
          
                    token.setNodeEnter(Clock.getCurrentTime());
          
          
                          //Signal the token of the process if needed
                    if(signalToken)
                         token.signal();
                         
                          //Create the job
                    ExecuteNodeJob job = new ExecuteNodeJob(token);
                    job.setNode(token.getNode());
                    
                    Calendar dataCorrente = Calendar.getInstance();
                    dataCorrente.add(Calendar.MINUTE, 1);
                    job.setDueDate(dataCorrente.getTime());
                    job.setExclusive(true);
          
          
                          //Send the job to the message service
                    MessageService messageService = (MessageService)Services.getCurrentService("message");
                    messageService.send(job);
                    token.lock(job.toString());        
          
          
                          //Return the process instance id to the main program
                    return subProcessInstance.getId();
          
               }
          

           

          I am testing this solution.

           

          Has anyone a better idea?

           

           

          I think this is a ploy help me to have multiple processes that running asynchronously.

           

          Best regards.

           

          Luca Zammarchi