Here is an example that shows how to invoke a sub-process from a main process.

A simple example shown in the discussion is considered here.


This example has a main process as shown below. It sends a couple of parameters (count and loopcondition) to the subprocess.

ScreenHunter_08 Mar. 01 09.41.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 and return the 'count' value to the main process. The 'loopcondition' can either be set inside this sub-process or can be retrieved from the parent process. In this example, it is set as a paramter in the main process.

ScreenHunter_09 Mar. 01 09.41.gif

How to run this example?


This example has two bpmn files (sampleLoopTest.bpmn for main process and looptest777.bpmn for sub-process loop) and a test file ( It might be easy to start with a HelloProcess project ( and import these files.

ScreenHunter_01 Mar. 01 11.47.gif



Here is the sample test code. The main process 'com.sample.bpmn.looptest'  is started as shown below which inturn invokes the sub-process.


public class LoopSubProcessTest {


   public static final void main(String[] args) {

        try {

            // load up the knowledge base

            KnowledgeBase kbase = readKnowledgeBase();

            StatefulKnowledgeSession ksession = createSession(kbase);

            KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory

                    .newFileLogger(ksession, "test");


            // Set the initial count and loopcondition

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

            params.put("count", 1);

            params.put("loopcondition", 4);


            //start the main process

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



        } catch (Throwable t) {




It is important to note that both the bpmn files need to be added to the KnowledgeBuilder as shown below.


IScreenHunter_11 Mar. 01 09.44.gif



Here are the results you would see after running the test program LoopSubProcessTest.

ScreenHunter_10 Mar. 01 09.44.gif