JBPM5 provides 'Multiple Instances' node that can be used to create multiple instances of reusable sub-processes.

 

Here is a simple example that shows how to send a colection of elements to sub-process nodes and invoke mutiple processes.

The example from the discussion http://community.jboss.org/thread/163105?tstart=0 is considered here to illustrate the usage.

 

 

It has a main process (sampleMultiLoopSubprocessTest.bpmn) that invokes multiple sub-processes (multilooptest777.bpmn).

The main process sends a list of parameters (initial count ) to the sub-process.

 

 

 

ScreenHunter_01 Mar. 05 15.53.gif

The sub-process goes through a loop incrementing the value of 'count'. Once the 'count' reaches the 'do until' loop condition value, it will exit the loop.

 

ScreenHunter_02 Mar. 05 15.54.gif

A list to contain the parameters that need to be sent to sub-processes are populated as shown below (MultiLoopProcessTest.java).

 

            Map<String, Object> params = new HashMap<String, Object>();

            List<Integer> myList = new ArrayList<Integer>();

 

            myList.add(process1Count);

            myList.add(process2Count);

            params.put("list", myList);

 

            ksession.startProcess("com.sample.bpmn.multilooptest",params);

 

The 'CollectionExpression' is set to 'list' as shown below,

 

ScreenHunter_03 Mar. 05 15.54.gif

The ProcessID is set to 'multilooptest777' as shown below to bind the sub-process.

ScreenHunter_04 Mar. 05 15.54.gif

 

How to run this example?

 

This example has two bpmn files (sampleMultiLoopSubprocessTest.bpmn for main process that invokes multiple processes and multilooptest777.bpmn for sub-process loop) and a test file (LoopSubProcessTest.java). It might be easy to start with a HelloProcess project (http://community.jboss.org/people/bpmn2user/blog/2011/02/27/helloprocess-example-using-jbpm5-eclipse-plug-in) and import these files.

 

ScreenHunter_06 Mar. 05 20.55.gif

 

Following results can be seen after successfully running this example.

 

ScreenHunter_05 Mar. 05 15.55.gif